-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1456 from ebkr/chunky-pt3
Use fflate to decompress package list chunks
- Loading branch information
Showing
3 changed files
with
15 additions
and
4 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 |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import * as zlib from 'zlib'; | ||
// Use third party library as Node's zlib is not available on TSMM. | ||
import { AsyncGunzip } from "fflate"; | ||
|
||
export function decompressArrayBuffer(compressed: ArrayBuffer, encoding = 'utf-8'): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
zlib.gunzip(compressed, (err, result) => { | ||
const gunzip = new AsyncGunzip((err, result) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
|
||
return resolve(result.toString(encoding)); | ||
const decoder = new TextDecoder(encoding); | ||
const decodedString = decoder.decode(result); | ||
return resolve(decodedString); | ||
}); | ||
|
||
gunzip.push(new Uint8Array(compressed), true); | ||
}); | ||
} |
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