Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add typescript definition #153

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
interface Header {
name: string
size: number
mode: number
mtime: Date
type: 'file' | 'link' | 'symlink' | 'directory' | 'block-device' | 'character-device' | 'fifo' | 'contiguous-file'
linkname: string
uid: number
gid: number
uname: string
gname: string
devmajor: number
devminor: number
pax?: object
}

type HeaderForPack = Partial<Header> & {
name: string
}

interface Pack extends NodeJS.ReadableStream {
entry(header: HeaderForPack, callback?: (error?: Error) => void): Sink
entry(
header: HeaderForPack,
buffer: string | Buffer,
callback?: (error?: Error) => void
): Sink
destroy(): void
finalize(): void
}

interface Sink extends NodeJS.WritableStream {
}

interface ExtractOptions {
filenameEncoding?: string
}

interface Source extends NodeJS.ReadableStream {
header: Header
offset: number
}

interface Extract extends NodeJS.WritableStream {
on(
event: 'entry',
callback: (
header: Header,
stream: Source,
next: () => void
) => void
): void
on(event: 'close', callback: () => void)
on(event: 'finish', callback: () => void)
on(event: 'error', callback: (error: Error) => void)
destroy(error?: Error): void
[Symbol.asyncIterator](): AsyncIterableIterator<Source>
}

interface Module {
pack(): Pack
extract(options?: ExtractOptions): Extract
}

export function pack(): Pack
export function extract(options?: ExtractOptions): Extract
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "3.1.6",
"description": "tar-stream is a streaming tar parser and generator and nothing else. It operates purely using streams which means you can easily extract/parse tarballs without ever hitting the file system.",
"main": "index.js",
"types": "index.d.ts",
"files": [
"*.js"
],
Expand Down