本文整理汇总了Python中io.FileIO.tell方法的典型用法代码示例。如果您正苦于以下问题:Python FileIO.tell方法的具体用法?Python FileIO.tell怎么用?Python FileIO.tell使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.FileIO
的用法示例。
在下文中一共展示了FileIO.tell方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_from_file
# 需要导入模块: from io import FileIO [as 别名]
# 或者: from io.FileIO import tell [as 别名]
def read_from_file(file_fd: io.FileIO, start: int, stop: int) -> bytes:
length = stop - start
assert length >= 0
file_fd.seek(start)
data = bytes()
while file_fd.tell() < stop:
read_data = file_fd.read(stop - file_fd.tell())
if read_data == b'':
raise ReachedEndOfFile('Read until the end of file')
data += read_data
assert len(data) == length
return data
示例2: load
# 需要导入模块: from io import FileIO [as 别名]
# 或者: from io.FileIO import tell [as 别名]
def load(self, file: FileIO):
self.ptr = file.tell()
self.is_leaf, self.keys = load(file)
ptr_num = len(self.keys)
if not self.is_leaf:
ptr_num += (ptr_num + 1)
ptrs = unpack('Q' * ptr_num, file.read(8 * ptr_num))
if self.is_leaf:
self.ptrs_value = list(ptrs)
else:
self.ptrs_value = list(ptrs[:len(self.keys)])
self.ptrs_child = list(ptrs[len(self.keys):])
self.size = file.tell() - self.ptr
示例3: read_from
# 需要导入模块: from io import FileIO [as 别名]
# 或者: from io.FileIO import tell [as 别名]
def read_from(cls, sector_file: io.FileIO) -> "SectorInfo":
# Save current position in file
tell = sector_file.tell()
# Go to end of file minus size of length.
sector_file.seek(-cls.length_parser.size, 2)
length, = cls.length_parser.unpack_from_file(sector_file)
print(length)
objects = []
if length:
# Go back to saved position
sector_file.seek(tell)
for _ in range(length):
objects.append(Object.read_from(sector_file))
return SectorObjects(objects=objects)
示例4: dump
# 需要导入模块: from io import FileIO [as 别名]
# 或者: from io.FileIO import tell [as 别名]
def dump(self, file: FileIO):
self.ptr = file.tell()
file.write(bytes(self))
示例5: load
# 需要导入模块: from io import FileIO [as 别名]
# 或者: from io.FileIO import tell [as 别名]
def load(self, file: FileIO):
self.ptr = file.tell()
indicator = file.read(1)
assert indicator in (OP, ED)
self.key, self.value = load(file)
self.size = file.tell() - self.ptr
示例6: File
# 需要导入模块: from io import FileIO [as 别名]
# 或者: from io.FileIO import tell [as 别名]
#.........这里部分代码省略.........
def close(self):
self.stream.close()
self.dir.close()
if self.data: self.data.close()
def fileno(self):
return self.fh
def isatty(self):
return False
def read(self, count=-1):
if count < 0: return self.readall()
elif count == 0: return b''
state = self.state
if state == File.HEADER:
previous_offset = self.offset
self.offset += count
result = self.zip_header[previous_offset:self.offset]
self.cursor += len(result)
if self.offset >= len(self.zip_header):
self.state = File.DATA
if not self.data: self._open_data_file()
return result
elif state == File.DATA:
result = self.data.read(count)
self.cursor += len(result)
if self.data.tell() >= self.data_len:
self.state = File.DESCRIPTOR
self.offset = 0
# empty data file (state will now be DESCRIPTOR)
if not result: return self.read(count)
return result
elif state == File.DESCRIPTOR:
previous_offset = self.offset
self.offset += count
result = self.descriptor[previous_offset:self.offset]
self.cursor += len(result)
if self.offset >= len(self.descriptor):
if self.cursor >= self.info.directory_offset:
self.state = File.DIRECTORY
self.dir.seek(0)
self.stream_offset = None
if self.data:
self.data.close()
self.data = None
else:
self.state = File.HEADER
self.offset = 0
self.stream_offset = self.stream.tell()
self._load_stream_item()
# descriptor is optional (state will now be HEADER or DIRECTORY)