Files @ e6f9a4843e49
Branch filter:

Location: Morevna/src/datafile.py

Laman
configurable log path
from hashtree import HashTree


BLOCK_SIZE=HashTree.BLOCK_SIZE


class DataFile:
	def __init__(self,fileHandle):
		self._lastIndex=0
		self._f=fileHandle

	@staticmethod
	def open(filename,mode="rb"):
		return DataFile(open(filename,mode=mode))

	def writeAt(self,i,blockData):
		if i!=self._lastIndex+1:
			self._f.seek(i*BLOCK_SIZE)
		self._f.write(blockData)
		self._lastIndex=i

	def readFrom(self,i,byteCount=BLOCK_SIZE):
		if i!=self._lastIndex+1:
			self._f.seek(i*BLOCK_SIZE)
		self._lastIndex=i
		return self._f.read(byteCount)

	def close(self):
		self._f.close()