1- import zstandard as zstd
2-
31
42class ParserError (Exception ):
53 pass
@@ -62,15 +60,23 @@ def get_frame(self, frame):
6260 offset = self .frame_offsets [curblock ][1 ]
6361 self .file .seek (offset , 0 )
6462
65- dctx = zstd .ZstdDecompressor ()
63+ if self .compression_type == 'zstd' :
64+ import zstandard as zstd
65+ dctx = zstd .ZstdDecompressor ()
6666
67- length = self .frame_offsets [curblock + 1 ][1 ] - self .frame_offsets [curblock ][1 ]
68- block = self .file .read (length )
69- block = dctx .stream_reader (block ).readall ()
67+ length = self .frame_offsets [curblock + 1 ][1 ] - self .frame_offsets [curblock ][1 ]
68+ block = self .file .read (length )
69+ block = dctx .stream_reader (block ).readall ()
7070
71- fidx = (frame - self .frame_offsets [curblock ][0 ]) * self .channel_count_per_frame
72- data = block [fidx :fidx + self .channel_count_per_frame ]
73- return data
71+ fidx = (frame - self .frame_offsets [curblock ][0 ]) * self .channel_count_per_frame
72+ data = block [fidx :fidx + self .channel_count_per_frame ]
73+ return data
74+ else :
75+ block = self .file .read ()
76+ fidx = frame * self .channel_count_per_frame
77+ data = block [fidx :fidx + self .channel_count_per_frame ]
78+ return data
79+
7480
7581 def _expand_sparse_ranges (self , data ):
7682 # TODO
@@ -105,7 +111,7 @@ def parse(f):
105111 raise ParserError ('unrecognized bit flags: %d' % bit_flags )
106112
107113 compression_type = compression_type_from_num (int_from_bytes (f .read (1 )))
108- if compression_type != 'zstd ' :
114+ if compression_type == 'gzip ' :
109115 raise ParserError ('unsupported compression type: %s' % compression_type )
110116
111117 num_compression_blocks = int_from_bytes (f .read (1 ))
@@ -119,6 +125,8 @@ def parse(f):
119125
120126 offset = channel_data_start
121127 frame_offsets = []
128+ if compression_type == 'none' :
129+ frame_offsets .append ((0 , offset ))
122130 for i in range (num_compression_blocks ):
123131 frame_number = int_from_bytes (f .read (4 ))
124132 length_of_block = int_from_bytes (f .read (4 ))
0 commit comments