MCPcopy Create free account
hub / github.com/ActiveState/code / read_file

Method read_file

recipes/Python/492212_dal4py/recipe-492212.py:115–127  ·  view source on GitHub ↗
(self, block)

Source from the content-addressed store, hash-verified

113
114 # Read From File
115 def read_file(self, block):
116 assert type(block) is int and 1 <= block <= self.__blocks
117 assert self.is_file(block)
118 data = self.__disk.read_file(block)
119 size = ord(data[2])
120 stream_length = (ord(data[size+3]) << 24) + (ord(data[size+4]) << 16)
121 stream_length += (ord(data[size+5]) << 8) + ord(data[size+6])
122 contents = data[size+3+4:]
123 pointers = [(ord(contents[index*2]) << 8) + ord(contents[index*2+1]) \
124 for index in range(len(contents) / 2)]
125 stream = ''.join([self.__disk.read_block(pointer) \
126 for pointer in pointers])
127 return stream[:stream_length]
128
129 # Write To File
130 def write_file(self, block, data):

Callers 7

__init__Method · 0.45
remove_fileMethod · 0.45
write_fileMethod · 0.45
emptyMethod · 0.45
nameMethod · 0.45
renameMethod · 0.45
__init__Method · 0.45

Calls 4

is_fileMethod · 0.95
rangeFunction · 0.85
read_blockMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected