def testBufferFile(): print "testing buffer file" buffersize = 17 writesize = 10 mstream = newFile("pyBufferFile.dat") offset = 55 bf = BufferFile.InitializeBufferFileInStream(mstream, buffersize, offset) testdata = "sample data off the top of my head " * 1000 position = 0 lt = len(testdata) for i in range(0, lt, writesize): chunk = testdata[i:i + writesize] bf.setBuffer(position, chunk) position += 1 #print position, lasti = i #position = 0 print bf = BufferFile.SetupFromExistingStream(mstream, offset) #for i in range(0, lt, writesize): for i in range(lasti, -1, -writesize): position -= 1 chunksize = min(writesize, lt - i) chunk = bf.getBuffer(position, chunksize) #position += 1 #print position, if chunk != testdata[i:i + writesize]: raise ValueError, "chunks don't match %s!=%s" % ( repr(chunk), repr(testdata[i:i + writesize])) print
def SetupFromExistingStream(file, StartSeek=0): result = LinkedFile(100, StartSeek) result.buffers = BufferFile.SetupFromExistingStream( file, StartSeek + result.headersize) result.fromfile = file result.readHeader() return result
def SetupFromExistingStream(fromfile, StartSeek=0): result = BplusTreeLong(fromfile, 33, 33, StartSeek) result.readHeader() result.buffers = BufferFile.SetupFromExistingStream( fromfile, StartSeek + result.headersize) if (result.buffers.buffersize != result.buffersize): raise BplusTreeException, "inner and outer buffer sizes should match " + repr( (result.buffers.buffersize, result.buffersize)) if result.rootSeek != NULLBUFFERNUMBER: result.root = BplusNode(result, None, None, True) result.root.LoadFromBuffer(result.rootSeek) return result