fix for chunk number calculation when unaligned - thanks to Daniel Lundin for the patch
This commit is contained in:
parent
ebd0e530db
commit
b09a95ccc1
@ -18,3 +18,4 @@ The following is a list of people who have contributed to
|
||||
- Joshua Roesslein (joshthecoder)
|
||||
- Gregg Lind (gregglind)
|
||||
- Michael Schurter (schmichael)
|
||||
- Daniel Lundin
|
||||
|
||||
@ -306,7 +306,7 @@ class GridFile(object):
|
||||
size = remainder
|
||||
|
||||
bytes = self.__buffer
|
||||
chunk_number = math.floor(self.__position / self.__chunk_size)
|
||||
chunk_number = (len(bytes) + self.__position) / self.__chunk_size
|
||||
|
||||
while len(bytes) < size:
|
||||
chunk = self.__collection.chunks.find_one({"files_id": self.__id, "n": chunk_number})
|
||||
|
||||
@ -406,5 +406,26 @@ class TestGridFile(unittest.TestCase):
|
||||
file = GridFile({"_id": "foobar", "filename": "foobar"}, self.db, "w")
|
||||
file.close()
|
||||
|
||||
def test_read_chunks_unaligned_buffer_size(self):
|
||||
self.db.fs.files.remove({})
|
||||
self.db.fs.chunks.remove({})
|
||||
|
||||
in_data = "This is a text that doesn't quite fit in a single 16-byte chunk."
|
||||
f = GridFile({"filename":"test", "chunkSize":16}, self.db, "w")
|
||||
f.write(in_data)
|
||||
f.close()
|
||||
|
||||
f = GridFile({"filename":"test"}, self.db)
|
||||
out_data = ''
|
||||
while 1:
|
||||
s = f.read(13)
|
||||
if not s:
|
||||
break
|
||||
out_data += s
|
||||
f.close()
|
||||
|
||||
self.assertEqual(in_data, out_data)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user