-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: make parser async and use native zlib decompression
- Loading branch information
Showing
10 changed files
with
111 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* @typedef {Object} Options | ||
* @property {import('cheminfo-types').Logger} [logger] - A potential logger | ||
*/ | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export async function inflate(zlibCompressedData) { | ||
// Strip the zlib header and footer | ||
const strippedData = zlibCompressedData.subarray(2, -4); // Remove 2-byte header and 4-byte Adler-32 footer | ||
|
||
const inputStream = new ReadableStream({ | ||
start(controller) { | ||
controller.enqueue(strippedData); | ||
controller.close(); | ||
}, | ||
}); | ||
|
||
const decompressedStream = inputStream.pipeThrough( | ||
new DecompressionStream('deflate-raw'), | ||
Check failure on line 13 in src/util/inflate.js GitHub Actions / nodejs / test (18)src/mzml/__tests__/parseMzML.test.js > parseMzML > read test.mzML
Check failure on line 13 in src/util/inflate.js GitHub Actions / nodejs / test (18)src/mzml/__tests__/parseMzML.test.js > parseMzML > read compressed 32bits
|
||
); | ||
|
||
const reader = decompressedStream.getReader(); | ||
const chunks = []; | ||
let totalLength = 0; | ||
|
||
while (true) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const { value, done } = await reader.read(); | ||
if (done) break; | ||
chunks.push(value); | ||
totalLength += value.length; | ||
} | ||
|
||
// Combine chunks into a single Uint8Array | ||
const decompressedData = new Uint8Array(totalLength); | ||
let offset = 0; | ||
for (const chunk of chunks) { | ||
decompressedData.set(chunk, offset); | ||
offset += chunk.length; | ||
} | ||
|
||
return decompressedData; | ||
} |