Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 2d707f4

Browse files
committed
actually use the offset in CompressedFPSource
1 parent 2c0086b commit 2d707f4

4 files changed

Lines changed: 7 additions & 10 deletions

File tree

bloscpack/append.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,9 @@ def append_fp(original_fp, new_content_fp, new_size, blosc_args=None):
112112
(METADATA_HEADER_LENGTH + metadata_header['max_meta_size'] +
113113
CHECKSUMS_LOOKUP[metadata_header['meta_checksum']].size
114114
if metadata is not None else 0))
115-
# seek to the final offset
116-
original_fp.seek(offsets[-1], 0)
117115
# decompress the last chunk
118116
compressed, blosc_header, digest = _read_compressed_chunk_fp(original_fp,
119-
checksum_impl)
117+
checksum_impl, offsets[-1])
120118
# TODO check digest
121119
decompressed = blosc.decompress(compressed)
122120
# figure out how many bytes we need to read to rebuild the last chunk

bloscpack/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def main():
511511
checksum_impl = bloscpack_header.checksum_impl
512512
# get the header of the first chunk
513513
_, blosc_header, _ = _read_compressed_chunk_fp(
514-
fp, checksum_impl)
514+
fp, checksum_impl, offsets[0])
515515
except ValueError as ve:
516516
log.error(str(ve) + "\n" +
517517
"This might not be a bloscpack compressed file.")

bloscpack/file_io.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def _write_offsets(output_fp, offsets):
298298
output_fp.write(encoded_offsets)
299299

300300

301-
def _read_compressed_chunk_fp(input_fp, checksum_impl):
301+
def _read_compressed_chunk_fp(input_fp, checksum_impl, offset):
302302
""" Read a compressed chunk from a file pointer.
303303
304304
Parameters
@@ -318,6 +318,7 @@ def _read_compressed_chunk_fp(input_fp, checksum_impl):
318318
the checksum of the chunk
319319
"""
320320
# read blosc header
321+
input_fp.seek(offset)
321322
blosc_header_raw = input_fp.read(BLOSC_HEADER_LENGTH)
322323
blosc_header = decode_blosc_header(blosc_header_raw)
323324
if log.LEVEL == log.DEBUG:
@@ -365,7 +366,7 @@ def __init__(self, input_fp):
365366

366367
def __iter__(self):
367368
for i in xrange(self.nchunks):
368-
compressed, header, digest = _read_compressed_chunk_fp(self.input_fp, self.checksum_impl)
369+
compressed, header, digest = _read_compressed_chunk_fp(self.input_fp, self.checksum_impl, self.offsets[i])
369370
yield compressed, digest
370371

371372

test/test_append.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,12 @@ def test_append_mix_shuffle():
366366
# now get the first and the last chunk and check that the shuffle doesn't
367367
# match
368368
bloscpack_header, offsets = reset_read_beginning(orig)[0:4:3]
369-
orig.seek(offsets[0])
370369
checksum_impl = CHECKSUMS_LOOKUP[bloscpack_header['checksum']]
371370
compressed_zero, blosc_header_zero, digest = \
372-
_read_compressed_chunk_fp(orig, checksum_impl)
371+
_read_compressed_chunk_fp(orig, checksum_impl, offsets[0])
373372
decompressed_zero = blosc.decompress(compressed_zero)
374-
orig.seek(offsets[-1])
375373
compressed_last, blosc_header_last, digest = \
376-
_read_compressed_chunk_fp(orig, checksum_impl)
374+
_read_compressed_chunk_fp(orig, checksum_impl, offsets[-1])
377375
decompressed_last = blosc.decompress(compressed_last)
378376
# first chunk has shuffle active
379377
nt.assert_equal(blosc_header_zero['flags'], 1)

0 commit comments

Comments
 (0)