rii-mango / NIFTI-Reader-JS

A JavaScript NIfTI file format reader.
MIT License
137 stars 30 forks source link

Enh/switch to fflate #19

Closed hanayik closed 1 year ago

hanayik commented 1 year ago

This PR removes the references to pako and uses fflate now. I have run tests locally and they all pass.

I chose to increment the minor version number to 0.6.0 since this is more than a bug fix/patch, but not significant enough to warrant a major version increment (no API changes).

output of tests:

  NIFTI-Reader-JS
    uncompressed 5D nifti-1 test
      ✔ isCompressed() should return false
      ✔ should not throw error when reading header
      ✔ dims[1] should be 1
      ✔ dims[2] should be 2
      ✔ dims[3] should be 3
      ✔ dims[4] should be 1
      ✔ dims[5] should be 3
      ✔ image size should equal 1 * 2 * 3 * 1 * 3
      ✔ image data checksum should equal 1033497386

  NIFTI-Reader-JS
    compressed 5D nifti-1 test
      ✔ isCompressed() should return true
      ✔ should not throw error when decompressing (64ms)
      ✔ should not throw error when reading header
      ✔ dims[1] should be 256
      ✔ dims[2] should be 256
      ✔ dims[3] should be 170
      ✔ dims[4] should be 1
      ✔ dims[5] should be 3
      ✔ image size should equal 33423360
      ✔ image data checksum should equal 1033497386 (126ms)

  NIFTI-Reader-JS
    nifti-1 big endian test
      ✔ isCompressed() should return true
      ✔ should not throw error when decompressing
      ✔ isNIFTI1() should return true
      ✔ should not throw error when reading header
      ✔ numBitsPerVoxel should be 32
      ✔ littleEndian should be false
      ✔ dims[1] should be 64
      ✔ dims[2] should be 64
      ✔ dims[3] should be 21
      ✔ image data checksum should equal 3243691439

  NIFTI-Reader-JS
    nifti-1 extension test
      ✔ should not throw error when decompressing
      ✔ isNIFTI1() should return true
extensionByteIndex: 360 esize: 384
ArrayBuffer {
  [Uint8Contents]: <00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54 46 2d 38 22 20 73 74 61 6e 64 61 6c 6f 6e 65 3d 22 6e 6f 22 3f 3e 3c 21 44 4f 43 54 59 50 45 20 4d 61 6e 67 6f 52 4f 49 20 53 59 53 54 45 4d 20 ... 276 more bytes>,
  byteLength: 376
}
      ✔ should not throw error when reading header
      ✔ hasExtension() should return true
      ✔ extension length should be 376 (384 - 8)
      ✔ should have one extension that is 376 bytes
      ✔ removed extension changes the vox offset
      ✔ removed extension updates the vox offset
      ✔ added extension updates vox_offset
      ✔ toArrayBuffer properly allocates extension byte array
extensionByteIndex: 360 esize: 384
ArrayBuffer {
  [Uint8Contents]: <00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54 46 2d 38 22 20 73 74 61 6e 64 61 6c 6f 6e 65 3d 22 6e 6f 22 3f 3e 3c 21 44 4f 43 54 59 50 45 20 4d 61 6e 67 6f 52 4f 49 20 53 59 53 54 45 4d 20 ... 276 more bytes>,
  byteLength: 376
}
      ✔ toArrayBuffer properly preserves extension bytes
extensionByteIndex: 360 esize: 384
ArrayBuffer {
  [Uint8Contents]: <00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54 46 2d 38 22 20 73 74 61 6e 64 61 6c 6f 6e 65 3d 22 6e 6f 22 3f 3e 3c 21 44 4f 43 54 59 50 45 20 4d 61 6e 67 6f 52 4f 49 20 53 59 53 54 45 4d 20 ... 276 more bytes>,
  byteLength: 376
}
extensionByteIndex: 744 esize: 32
ArrayBuffer {
  [Uint8Contents]: <08 00 00 00 08 00 00 00 08 00 00 00 08 00 00 00 08 00 00 00 08 00 00 00>,
  byteLength: 24
}
      ✔ extensions can be added and serialized
extensionByteIndex: 360 esize: 384
ArrayBuffer {
  [Uint8Contents]: <00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54 46 2d 38 22 20 73 74 61 6e 64 61 6c 6f 6e 65 3d 22 6e 6f 22 3f 3e 3c 21 44 4f 43 54 59 50 45 20 4d 61 6e 67 6f 52 4f 49 20 53 59 53 54 45 4d 20 ... 276 more bytes>,
  byteLength: 376
}
      ✔ extensions can be removed by index
extensionByteIndex: 360 esize: 32
ArrayBuffer {
  [Uint8Contents]: <00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>,
  byteLength: 24
}
extensionByteIndex: 392 esize: 384
ArrayBuffer {
  [Uint8Contents]: <00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54 46 2d 38 22 20 73 74 61 6e 64 61 6c 6f 6e 65 3d 22 6e 6f 22 3f 3e 3c 21 44 4f 43 54 59 50 45 20 4d 61 6e 67 6f 52 4f 49 20 53 59 53 54 45 4d 20 ... 276 more bytes>,
  byteLength: 376
}
      ✔ extensions can be inserted and serialized

  NIFTI-Reader-JS
    compressed nifti-1 test
      ✔ isCompressed() should return true
      ✔ should not throw error when decompressing
      ✔ isNIFTI1() should return true
      ✔ should not throw error when reading header
      ✔ dims[1] should be 91
      ✔ dims[2] should be 109
      ✔ dims[3] should be 91
      ✔ hasExtension() should return false
      ✔ image data checksum should equal 1033497386

  NIFTI-Reader-JS
    nifti-1 little endian test
      ✔ isCompressed() should return true
      ✔ should not throw error when decompressing
      ✔ isNIFTI1() should return true
      ✔ should not throw error when reading header
      ✔ numBitsPerVoxel should be 32
      ✔ littleEndian should be true
      ✔ dims[1] should be 64
      ✔ dims[2] should be 64
      ✔ dims[3] should be 21
      ✔ image data checksum should equal 4006845507

  NIFTI-Reader-JS
    uncompressed nifti-1 hdr/img pair test
      ✔ isCompressed() should return true
      ✔ should not throw error when decompressing header
      ✔ should not throw error when decompressing image
      ✔ isNIFTI1() should return true
      ✔ isNIFTI() should return true
      ✔ should not throw error when reading header
      ✔ dims[1] should be 79
      ✔ dims[2] should be 67
      ✔ dims[3] should be 64
      ✔ image data checksum should equal 692149477
      ✔ data returned from toArrayBuffer preserves all nifti-1 properties

  NIFTI-Reader-JS
    uncompressed nifti-1 test
      ✔ isCompressed() should return false
      ✔ isNIFTI1() should return true
      ✔ isNIFTI() should return true
      ✔ should not throw error when reading header
      ✔ dims[1] should be 91
      ✔ dims[2] should be 109
      ✔ dims[3] should be 91
      ✔ image data checksum should equal 1033497386
      ✔ data returned from toArrayBuffer preserves all nifti-1 properties

  NIFTI-Reader-JS
    nifti-2 extension test
      ✔ should not throw error when reading header
extensionByteIndex: 552 esize: 32
ArrayBuffer {
  [Uint8Contents]: <08 00 00 00 08 00 00 00 08 00 00 00 08 00 00 00 08 00 00 00 08 00 00 00>,
  byteLength: 24
}
      ✔ extensions can be added and serialized

  NIFTI-Reader-JS
    compressed nifti-2 test
      ✔ isCompressed() should return true
      ✔ should not throw error when decompressing
      ✔ isNIFTI1() should return false
      ✔ isNIFTI2() should return true
      ✔ should not throw error when reading header
      ✔ dims[1] should be 91
      ✔ dims[2] should be 109
      ✔ dims[3] should be 91
      ✔ image data checksum should equal 471047545
      ✔ data returned from toArrayBuffer preserves all nifti-2 properties

  NIFTI-Reader-JS
    uncompressed nifti-2 hdr/img pair test
      ✔ isCompressed() should return true
      ✔ should not throw error when decompressing header
      ✔ should not throw error when decompressing image
      ✔ isNIFTI2() should return true
      ✔ isNIFTI() should return true
      ✔ should not throw error when reading header
      ✔ dims[1] should be 79
      ✔ dims[2] should be 67
      ✔ dims[3] should be 64
      ✔ image data checksum should equal 692149477
      ✔ data returned from toArrayBuffer preserves all nifti-2 properties

  NIFTI-Reader-JS
    not-nifti test
      ✔ isCompressed() should return false
      ✔ isNIFTI() should return false
That file does not appear to be NIFTI!
      ✔ readHeader() should return null

  108 passing (360ms)