forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤖 Merge PR DefinitelyTyped#70963 [zip-stream] Add types for zip-strea…
…m by @MysteryBlokHed
- Loading branch information
1 parent
59b152e
commit 08f9649
Showing
5 changed files
with
177 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
* | ||
!**/*.d.ts | ||
!**/*.d.cts | ||
!**/*.d.mts | ||
!**/*.d.*.ts |
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,80 @@ | ||
/// <reference types="node" /> | ||
import { ZipArchiveEntry, ZipArchiveOutputStream } from "compress-commons"; | ||
import { Stream, TransformOptions } from "readable-stream"; | ||
|
||
import { Stream as NodeStream } from "node:stream"; | ||
import { ZlibOptions } from "node:zlib"; | ||
|
||
export interface ZipStreamOptions extends TransformOptions { | ||
/** | ||
* Prepends a forward slash to archive file paths | ||
* @default false | ||
*/ | ||
namePrependSlash?: boolean | undefined; | ||
/** Sets the zip archive comment */ | ||
comment?: string | undefined; | ||
/** | ||
* Forces archive to use local file times instead of UTC | ||
* @default false | ||
*/ | ||
forceLocalTime?: boolean | undefined; | ||
/** | ||
* Forces the archive to have Zip64 headers | ||
* @default false | ||
*/ | ||
forceZip64?: boolean | undefined; | ||
/** | ||
* Sets the compression method to STORE | ||
* @default false | ||
*/ | ||
store?: boolean | undefined; | ||
/** | ||
* Options passed to Zlib | ||
* @see {@link ZlibOptions} | ||
*/ | ||
zlib?: ZlibOptions | undefined; | ||
/** @see {@link ZlibOptions.level} */ | ||
level?: number | undefined; | ||
} | ||
|
||
export interface FileDataInput { | ||
/** Entry type. Defaults to `directory` if name ends with forward slash */ | ||
type?: "file" | "directory" | "symlink" | undefined; | ||
/** Entry name, including internal path */ | ||
name?: string | null | undefined; | ||
namePrependSlash?: boolean | undefined; | ||
linkname?: string | null | undefined; | ||
/** Sets the entry date. Defaults to current date */ | ||
date?: string | Date | null | undefined; | ||
/** Sets the entry permissions. Defaults to D:0755/F:0644 */ | ||
mode?: number | null | undefined; | ||
/** Sets the compression method to STORE */ | ||
store?: boolean | undefined; | ||
/** Sets the entry comment */ | ||
comment?: string | undefined; | ||
} | ||
|
||
export interface FileDataNormalized { | ||
type: "file" | "directory" | "symlink"; | ||
name: string | null; | ||
namePrependSlash: boolean; | ||
linkname: string | null; | ||
date: Date | null; | ||
store: boolean; | ||
comment: string; | ||
} | ||
|
||
export default class ZipStream extends ZipArchiveOutputStream { | ||
constructor(options?: ZipStreamOptions); | ||
|
||
_normalizeFileData(data: FileDataInput): FileDataNormalized; | ||
|
||
// @ts-expect-error TS2416 since overrided function signature is incompatible with extended class | ||
entry( | ||
source?: Buffer | Stream | NodeStream | string | null, | ||
data?: FileDataInput, | ||
callback?: (err: Error | null, ae?: ZipArchiveEntry) => void, | ||
): this | undefined; | ||
|
||
finalize(): void; | ||
} |
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,23 @@ | ||
{ | ||
"private": true, | ||
"name": "@types/zip-stream", | ||
"version": "7.0.9999", | ||
"type": "module", | ||
"projects": [ | ||
"https://github.com/archiverjs/node-zip-stream" | ||
], | ||
"dependencies": { | ||
"@types/compress-commons": "*", | ||
"@types/node": "*", | ||
"@types/readable-stream": "*" | ||
}, | ||
"devDependencies": { | ||
"@types/zip-stream": "workspace:." | ||
}, | ||
"owners": [ | ||
{ | ||
"name": "Adam Thompson-Sharpe", | ||
"githubUsername": "MysteryBlokHed" | ||
} | ||
] | ||
} |
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,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "node16", | ||
"lib": ["es6"], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictFunctionTypes": true, | ||
"strictNullChecks": true, | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.d.ts", | ||
"zip-stream-tests.ts" | ||
] | ||
} |
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,52 @@ | ||
import ZipStream from "zip-stream"; | ||
|
||
new ZipStream(); | ||
new ZipStream({}); | ||
new ZipStream({ | ||
namePrependSlash: true, | ||
comment: "Foobar", | ||
forceLocalTime: true, | ||
forceZip64: true, | ||
store: true, | ||
level: 123, | ||
}); | ||
// Testing Zlib options | ||
new ZipStream({ zlib: { flush: 123 } }); | ||
// Testing transform options | ||
new ZipStream({ defaultEncoding: "utf-8" }); | ||
|
||
const archive = new ZipStream(); | ||
archive.entry("abc"); | ||
archive.entry("abc", {}); | ||
archive.entry("abc", { | ||
type: "directory", | ||
name: "foo/", | ||
namePrependSlash: false, | ||
linkname: "foobar", | ||
date: "2024-10-21", | ||
mode: 123, | ||
store: true, | ||
comment: "Foobar", | ||
}); | ||
archive.entry("abc", { date: new Date() }); | ||
archive.entry("abc", {}, (err, entry) => { | ||
if (err) throw err; | ||
entry!; // $ExpectType ZipArchiveEntry | ||
}); | ||
|
||
archive.finalize(); | ||
|
||
// Examples below adapted from README | ||
// See https://github.com/archiverjs/node-zip-stream?tab=readme-ov-file#usage | ||
|
||
archive.on("error", err => { | ||
throw err; | ||
}); | ||
|
||
archive.entry("string contents", { name: "string.txt" }, (err, entry) => { | ||
if (err) throw err; | ||
archive.entry(null, { name: "directory/" }, (err, entry) => { | ||
if (err) throw err; | ||
archive.finish(); | ||
}); | ||
}); |