本文整理汇总了Python中pyglet.compat.BytesIO.read方法的典型用法代码示例。如果您正苦于以下问题:Python BytesIO.read方法的具体用法?Python BytesIO.read怎么用?Python BytesIO.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyglet.compat.BytesIO
的用法示例。
在下文中一共展示了BytesIO.read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load
# 需要导入模块: from pyglet.compat import BytesIO [as 别名]
# 或者: from pyglet.compat.BytesIO import read [as 别名]
def load(filename, file=None, decoder=None, batch=None):
"""Load a 3D model from a file.
:Parameters:
`filename` : str
Used to guess the model format, and to load the file if `file` is
unspecified.
`file` : file-like object or None
Source of model data in any supported format.
`decoder` : ModelDecoder or None
If unspecified, all decoders that are registered for the filename
extension are tried. If none succeed, the exception from the
first decoder is raised.
`batch` : Batch or None
An optional Batch instance to add this model to.
:rtype: Model
"""
if not file:
file = open(filename, 'rb')
if not hasattr(file, 'seek'):
file = BytesIO(file.read())
try:
if decoder:
return decoder.decode(file, filename, batch)
else:
first_exception = None
for decoder in _codecs.get_decoders(filename):
try:
model = decoder.decode(file, filename, batch)
return model
except _codecs.ModelDecodeException as e:
if (not first_exception or
first_exception.exception_priority < e.exception_priority):
first_exception = e
file.seek(0)
if not first_exception:
raise _codecs.ModelDecodeException('No decoders are available'
'for this model format.')
raise first_exception
finally:
file.close()
示例2: StaticMemorySource
# 需要导入模块: from pyglet.compat import BytesIO [as 别名]
# 或者: from pyglet.compat.BytesIO import read [as 别名]
class StaticMemorySource(StaticSource):
"""Helper class for default implementation of `StaticSource`. Do not use
directly."""
def __init__(self, data, audio_format):
"""Construct a memory source over the given data buffer.
"""
self._file = BytesIO(data)
self._max_offset = len(data)
self.audio_format = audio_format
self._duration = len(data) / float(audio_format.bytes_per_second)
def seek(self, timestamp):
offset = int(timestamp * self.audio_format.bytes_per_second)
# Align to sample
if self.audio_format.bytes_per_sample == 2:
offset &= 0xfffffffe
elif self.audio_format.bytes_per_sample == 4:
offset &= 0xfffffffc
self._file.seek(offset)
def get_audio_data(self, bytes_):
offset = self._file.tell()
timestamp = float(offset) / self.audio_format.bytes_per_second
# Align to sample size
if self.audio_format.bytes_per_sample == 2:
bytes_ &= 0xfffffffe
elif self.audio_format.bytes_per_sample == 4:
bytes_ &= 0xfffffffc
data = self._file.read(bytes_)
if not len(data):
return None
duration = float(len(data)) / self.audio_format.bytes_per_second
return AudioData(data, len(data), timestamp, duration, list())
示例3: __init__
# 需要导入模块: from pyglet.compat import BytesIO [as 别名]
# 或者: from pyglet.compat.BytesIO import read [as 别名]
def __init__(self, file):
if not hasattr(file, 'seek'):
file = BytesIO(file.read())
super(RIFFFile, self).__init__(file, 0)