Пример #1
0
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
Пример #2
0
def InitializeLinkedFileInStream(file, buffersize, StartSeek=0):
    result = LinkedFile(buffersize, StartSeek)
    result.fromfile = file
    result.setHeader()
    result.buffers = BufferFile.InitializeBufferFileInStream(
        file, buffersize + BUFFEROVERHEAD, StartSeek + result.headersize)
    return result
def InitializeInStream(fromfile,
                       KeyLength,
                       NodeSize,
                       CultureId=INVARIANTCULTUREID,
                       StartSeek=0):
    result = BplusTreeLong(fromfile, NodeSize, KeyLength, StartSeek, CultureId)
    result.setHeader()
    result.buffers = BufferFile.InitializeBufferFileInStream(
        fromfile, result.buffersize, StartSeek + result.headersize)
    return result