File tree Expand file tree Collapse file tree 5 files changed +106
-0
lines changed
Expand file tree Collapse file tree 5 files changed +106
-0
lines changed Original file line number Diff line number Diff line change 1+ *
2+ ! ** /* .d.ts
3+ ! ** /* .d.cts
4+ ! ** /* .d.mts
5+ ! ** /* .d. * .ts
Original file line number Diff line number Diff line change 1+ /// <reference types="node" />
2+ export interface CompressOptions {
3+ /** Compression level from 1 (fastest) to 9 (best). Default is 9. */
4+ level ?: number ;
5+ /** Buffering behavior, e.g., 'auto'. */
6+ buffering ?: 'auto' | string ;
7+ }
8+
9+ export interface DecompressOptions {
10+ /** Use less memory during decompression at the cost of speed. */
11+ small ?: boolean ;
12+ }
13+
14+ export function compress ( input : string | Buffer | Uint8Array , options ?: CompressOptions ) : Buffer ;
15+
16+ export function decompress ( input : Buffer | Uint8Array , options ?: DecompressOptions ) : Buffer ;
17+
18+ export function compressAsync ( input : string | Buffer | Uint8Array , options ?: CompressOptions ) : Promise < Buffer > ;
19+
20+ export function decompressAsync ( input : Buffer | Uint8Array , options ?: DecompressOptions ) : Promise < Buffer > ;
Original file line number Diff line number Diff line change 1+ import * as bzip2 from 'node-bzip2' ;
2+
3+ interface Result {
4+ data : Buffer | null ;
5+ error : Error | null ;
6+ }
7+
8+ async function doCompress ( ) : Promise < Result > {
9+ try {
10+ const input = "Hello, world!" ;
11+ const compressed = await bzip2 . compressAsync ( input , { level : 9 } ) ;
12+ return { data : compressed , error : null } ;
13+ } catch ( e ) {
14+ return { data : null , error : e as Error } ;
15+ }
16+ }
17+
18+ async function doDecompress ( cResult : Result ) : Promise < Result > {
19+ if ( cResult . error || ! cResult . data ) return cResult ;
20+ try {
21+ const decompressed = await bzip2 . decompressAsync ( cResult . data ) ;
22+ return { data : decompressed , error : null } ;
23+ } catch ( e ) {
24+ return { data : null , error : e as Error } ;
25+ }
26+ }
27+
28+ async function doTest ( ) {
29+ const cResult = await doCompress ( ) ;
30+ const dResult = await doDecompress ( cResult ) ;
31+
32+ if ( ! dResult . error && dResult . data ?. toString ( ) === "Hello, world!" ) {
33+ console . log ( "Success" ) ;
34+ } else {
35+ console . log ( "Failure" , dResult . error ) ;
36+ }
37+ }
38+
39+ doTest ( ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "private" : true ,
3+ "name" : " @types/node-bzip2" ,
4+ "version" : " 1.0.9999" ,
5+ "projects" : [
6+ " https://github.com/WilliamVenner/node-bzip2"
7+ ],
8+ "dependencies" : {
9+ "@types/node" : " *"
10+ },
11+ "devDependencies" : {
12+ "@types/node-bzip2" : " workspace:."
13+ },
14+ "owners" : [
15+ {
16+ "name" : " Sheryl Gavin" ,
17+ "githubUsername" : " shadowslasher410"
18+ }
19+ ]
20+ }
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "module" : " node16" ,
4+ "lib" : [
5+ " es6"
6+ ],
7+ "noImplicitAny" : true ,
8+ "noImplicitThis" : true ,
9+ "strictFunctionTypes" : true ,
10+ "strictNullChecks" : true ,
11+ "types" : [],
12+ "noEmit" : true ,
13+ "forceConsistentCasingInFileNames" : true ,
14+ "paths" : {
15+ "node-bzip2" : [" ./index.d.ts" ]
16+ }
17+ },
18+ "files" : [
19+ " index.d.ts" ,
20+ " node-bzip2-tests.ts"
21+ ]
22+ }
You can’t perform that action at this time.
0 commit comments