Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions bloscpack/append.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ def append_fp(original_fp, new_content_fp, new_size, blosc_args=None):
(METADATA_HEADER_LENGTH + metadata_header['max_meta_size'] +
CHECKSUMS_LOOKUP[metadata_header['meta_checksum']].size
if metadata is not None else 0))
# seek to the final offset
original_fp.seek(offsets[-1], 0)
# decompress the last chunk
compressed, blosc_header, digest = _read_compressed_chunk_fp(original_fp,
checksum_impl)
checksum_impl, offsets[-1])
# TODO check digest
decompressed = blosc.decompress(compressed)
# figure out how many bytes we need to read to rebuild the last chunk
Expand Down
3 changes: 2 additions & 1 deletion bloscpack/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,9 @@ def main():
_read_beginning(fp)
checksum_impl = bloscpack_header.checksum_impl
# get the header of the first chunk
# pass -1 to avoid seeking
_, blosc_header, _ = _read_compressed_chunk_fp(
fp, checksum_impl)
fp, checksum_impl, -1)
except ValueError as ve:
log.error(str(ve) + "\n" +
"This might not be a bloscpack compressed file.")
Expand Down
8 changes: 6 additions & 2 deletions bloscpack/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def _write_offsets(output_fp, offsets):
output_fp.write(encoded_offsets)


def _read_compressed_chunk_fp(input_fp, checksum_impl):
def _read_compressed_chunk_fp(input_fp, checksum_impl, offset):
""" Read a compressed chunk from a file pointer.

Parameters
Expand All @@ -307,6 +307,8 @@ def _read_compressed_chunk_fp(input_fp, checksum_impl):
the file pointer to read the chunk from
checksum_impl : Checksum
the checksum that has been used
offset: int
the offset for the file pointer

Returns
-------
Expand All @@ -318,6 +320,8 @@ def _read_compressed_chunk_fp(input_fp, checksum_impl):
the checksum of the chunk
"""
# read blosc header
if offset >= 0:
input_fp.seek(offset)
blosc_header_raw = input_fp.read(BLOSC_HEADER_LENGTH)
blosc_header = decode_blosc_header(blosc_header_raw)
if log.LEVEL == log.DEBUG:
Expand Down Expand Up @@ -365,7 +369,7 @@ def __init__(self, input_fp):

def __iter__(self):
for i in xrange(self.nchunks):
compressed, header, digest = _read_compressed_chunk_fp(self.input_fp, self.checksum_impl)
compressed, header, digest = _read_compressed_chunk_fp(self.input_fp, self.checksum_impl, self.offsets[i])
yield compressed, digest


Expand Down
6 changes: 2 additions & 4 deletions test/test_append.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,12 @@ def test_append_mix_shuffle():
# now get the first and the last chunk and check that the shuffle doesn't
# match
bloscpack_header, offsets = reset_read_beginning(orig)[0:4:3]
orig.seek(offsets[0])
checksum_impl = CHECKSUMS_LOOKUP[bloscpack_header['checksum']]
compressed_zero, blosc_header_zero, digest = \
_read_compressed_chunk_fp(orig, checksum_impl)
_read_compressed_chunk_fp(orig, checksum_impl, offsets[0])
decompressed_zero = blosc.decompress(compressed_zero)
orig.seek(offsets[-1])
compressed_last, blosc_header_last, digest = \
_read_compressed_chunk_fp(orig, checksum_impl)
_read_compressed_chunk_fp(orig, checksum_impl, offsets[-1])
decompressed_last = blosc.decompress(compressed_last)
# first chunk has shuffle active
nt.assert_equal(blosc_header_zero['flags'], 1)
Expand Down