本文整理汇总了Python中typing.BinaryIO.tell方法的典型用法代码示例。如果您正苦于以下问题:Python BinaryIO.tell方法的具体用法?Python BinaryIO.tell怎么用?Python BinaryIO.tell使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typing.BinaryIO
的用法示例。
在下文中一共展示了BinaryIO.tell方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put
# 需要导入模块: from typing import BinaryIO [as 别名]
# 或者: from typing.BinaryIO import tell [as 别名]
def put(
self, namespace: str, metadata: Dict[str, Any], bytes_io: BinaryIO,
) -> None:
"""Store a file (``bytes_io``) inside ``namespace``."""
if bytes_io.tell():
bytes_io.seek(0)
outdir = self._dir_of(namespace)
if not outdir.exists():
outdir.mkdir(parents=True) # Create namespace directory as needed
outfile = outdir / self._get_filename(metadata)
with open(str(outfile), mode='wb', buffering=MEGABYTE) as writer:
while True:
chunk = bytes_io.read(MEGABYTE)
if chunk:
writer.write(chunk)
else:
break
assert outfile.lstat().st_size == metadata['length']
示例2: _read_sequences
# 需要导入模块: from typing import BinaryIO [as 别名]
# 或者: from typing.BinaryIO import tell [as 别名]
def _read_sequences(f: BinaryIO, off, count) -> List[MDLSequence]:
"""Split this off to decrease stack in main parse method."""
f.seek(off)
sequences = [None] * count # type: List[MDLSequence]
for i in range(count):
start_pos = f.tell()
(
base_ptr,
label_pos,
act_name_pos,
flags,
_, # Seems to be a pointer.
act_weight,
event_count,
event_pos,
) = str_read('8i', f)
bbox_min = str_readvec(f)
bbox_max = str_readvec(f)
# Skip 20 ints, 9 floats to get to keyvalues = 29*4 bytes
# Then 8 unused ints.
(
keyvalue_pos,
keyvalue_size,
) = str_read('116xii32x', f)
end_pos = f.tell()
f.seek(start_pos + event_pos)
events = [None] * event_count # type: List[SeqEvent]
for j in range(event_count):
event_start = f.tell()
(
event_cycle,
event_index,
event_flags,
event_options,
event_nameloc,
) = str_read('fii64si', f)
event_end = f.tell()
# There are two event systems.
if event_flags == 1 << 10:
# New system, name in the file.
event_name = read_nullstr(f, event_start + event_nameloc)
if event_name.isdigit():
try:
event_type = ANIM_EVENT_BY_INDEX[int(event_name)]
except KeyError:
raise ValueError('Unknown event index!')
else:
try:
event_type = ANIM_EVENT_BY_NAME[event_name]
except KeyError:
# NPC-specific events, declared dynamically.
event_type = event_name
else:
# Old system, index.
try:
event_type = ANIM_EVENT_BY_INDEX[event_index]
except KeyError:
# raise ValueError('Unknown event index!')
print('Unknown: ', event_index, event_options.rstrip(b'\0'))
continue
f.seek(event_end)
events[j] = SeqEvent(
type=event_type,
cycle=event_cycle,
options=event_options.rstrip(b'\0').decode('ascii')
)
if keyvalue_size:
keyvalues = read_nullstr(f, start_pos + keyvalue_pos)
else:
keyvalues = ''
sequences[i] = MDLSequence(
label=read_nullstr(f, start_pos + label_pos),
act_name=read_nullstr(f, start_pos + act_name_pos),
flags=flags,
act_weight=act_weight,
events=events,
bbox_min=bbox_min,
bbox_max=bbox_max,
keyvalues=keyvalues,
)
f.seek(end_pos)
return sequences
示例3: _load
# 需要导入模块: from typing import BinaryIO [as 别名]
# 或者: from typing.BinaryIO import tell [as 别名]
def _load(self, f: BinaryIO):
"""Read data from the MDL file."""
assert f.tell() == 0, "Doesn't begin at start?"
if f.read(4) != b'IDST':
raise ValueError('Not a model!')
(
self.version,
name,
file_len,
# 4 bytes are unknown...
) = str_read('i 4x 64s i', f)
if not 44 <= self.version <= 49:
raise ValueError('Unknown MDL version {}!'.format(self.version))
self.name = name.rstrip(b'\0').decode('ascii')
self.eye_pos = str_readvec(f)
self.illum_pos = str_readvec(f)
# Approx dimensions
self.hull_min = str_readvec(f)
self.hull_max = str_readvec(f)
self.view_min = str_readvec(f)
self.view_max = str_readvec(f)
# Break up the reading a bit to limit the stack size.
(
flags,
bone_count,
bone_off,
bone_controller_count, bone_controller_off,
hitbox_count, hitbox_off,
anim_count, anim_off,
sequence_count, sequence_off,
) = str_read('11I', f)
self.flags = Flags(flags)
(
activitylistversion, eventsindexed,
texture_count, texture_offset,
cdmat_count, cdmat_offset,
skinref_count, skinref_ind, skinfamily_count,
bodypart_count, bodypart_offset,
attachment_count, attachment_offset,
) = str_read('13i', f)
(
localnode_count,
localnode_index,
localnode_name_index,
# mstudioflexdesc_t
flexdesc_count,
flexdesc_index,
# mstudioflexcontroller_t
flexcontroller_count,
flexcontroller_index,
# mstudioflexrule_t
flexrules_count,
flexrules_index,
# IK probably refers to inverse kinematics
# mstudioikchain_t
ikchain_count,
ikchain_index,
# Information about any "mouth" on the model for speech animation
# More than one sounds pretty creepy.
# mstudiomouth_t
mouths_count,
mouths_index,
# mstudioposeparamdesc_t
localposeparam_count,
localposeparam_index,
) = str_read('15I', f)
# VDC:
# For anyone trying to follow along, as of this writing,
# the next "surfaceprop_index" value is at position 0x0134 (308)
# from the start of the file.
assert f.tell() == 308, 'Offset wrong? {} != 308 {}'.format(f.tell(), f)
(
# Surface property value (single null-terminated string)
surfaceprop_index,
# Unusual: In this one index comes first, then count.
# Key-value data is a series of strings. If you can't find
# what you're interested in, check the associated PHY file as well.
keyvalue_index,
#.........这里部分代码省略.........