@@ -239,13 +239,13 @@ hdf5.Variable = class {
239
239
}
240
240
const data = new Uint8Array ( data_size * item_size ) ;
241
241
for ( const node of tree . nodes ) {
242
- if ( node . filterMask !== 0 ) {
243
- return null ;
244
- }
245
242
let chunk = node . data ;
246
243
if ( this . _filterPipeline ) {
247
- for ( const filter of this . _filterPipeline . filters ) {
248
- chunk = filter . decode ( chunk ) ;
244
+ for ( let i = 0 ; i < this . _filterPipeline . filters . length ; i ++ ) {
245
+ if ( ( node . filterMask & ( 1 << i ) ) === 0 ) {
246
+ const filter = this . _filterPipeline . filters [ i ] ;
247
+ chunk = filter . decode ( chunk ) ;
248
+ }
249
249
}
250
250
}
251
251
const chunk_offset = node . fields . map ( ( x ) => x . toNumber ( ) ) ;
@@ -1364,14 +1364,70 @@ hdf5.Filter = class {
1364
1364
1365
1365
decode ( data ) {
1366
1366
switch ( this . id ) {
1367
- case 1 : { // gzip
1368
- const archive = zip . Archive . open ( data ) ;
1369
- return archive . entries . get ( '' ) . peek ( ) ;
1367
+ case 1 : return this . _deflate ( data ) ;
1368
+ case 32000 : return this . _lzf ( data ) ;
1369
+ default : throw new hdf5 . Error ( `Unsupported filter '${ this . id } :${ this . name } '.` ) ;
1370
+ }
1371
+ }
1372
+
1373
+ _deflate ( input ) {
1374
+ const archive = zip . Archive . open ( input ) ;
1375
+ return archive . entries . get ( '' ) . peek ( ) ;
1376
+ }
1377
+
1378
+ _lzf ( input ) {
1379
+ let i = 0 ;
1380
+ let o = 0 ;
1381
+ while ( i < input . length ) {
1382
+ let c = input [ i ++ ] ;
1383
+ if ( c < ( 1 << 5 ) ) {
1384
+ c ++ ;
1385
+ i += c ;
1386
+ o += c ;
1387
+ if ( i > input . length ) {
1388
+ throw new Error ( 'Invalid LZF compressed data.' ) ;
1389
+ }
1390
+ } else {
1391
+ let length = c >> 5 ;
1392
+ if ( i >= input . length ) {
1393
+ throw new Error ( 'Invalid LZF compressed data.' ) ;
1394
+ }
1395
+ if ( length === 7 ) {
1396
+ length += input [ i ++ ] ;
1397
+ if ( i >= input . length ) {
1398
+ throw new Error ( 'Invalid LZF compressed data.' ) ;
1399
+ }
1400
+ }
1401
+ const ref = ( o - ( ( c & 0x1f ) << 8 ) - 1 ) - input [ i ++ ] ;
1402
+ if ( ref < 0 ) {
1403
+ throw new Error ( 'Invalid LZF compressed data.' ) ;
1404
+ }
1405
+ o += length + 2 ;
1370
1406
}
1371
- default : {
1372
- throw new hdf5 . Error ( `Unsupported filter '${ this . name } '.` ) ;
1407
+ }
1408
+ const output = new Uint8Array ( o ) ;
1409
+ i = 0 ;
1410
+ o = 0 ;
1411
+ while ( i < input . length ) {
1412
+ let c = input [ i ++ ] ;
1413
+ if ( c < ( 1 << 5 ) ) {
1414
+ c ++ ;
1415
+ output . set ( input . subarray ( i , i + c ) , o ) ;
1416
+ i += c ;
1417
+ o += c ;
1418
+ } else {
1419
+ let length = c >> 5 ;
1420
+ if ( length === 7 ) {
1421
+ length += input [ i ++ ] ;
1422
+ }
1423
+ length += 2 ;
1424
+ let ref = o - ( ( c & 0x1f ) << 8 ) - 1 - input [ i ++ ] ;
1425
+ do {
1426
+ output [ o ++ ] = output [ ref ++ ] ;
1427
+ } while ( -- length ) ;
1373
1428
}
1374
1429
}
1430
+ return output ;
1375
1431
}
1376
1432
} ;
1377
1433
0 commit comments