diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..26296b5 --- /dev/null +++ b/index.d.ts @@ -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
& { + 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 +} + +interface Module { + pack(): Pack + extract(options?: ExtractOptions): Extract +} + +export function pack(): Pack +export function extract(options?: ExtractOptions): Extract diff --git a/package.json b/package.json index e16048f..88c5e19 100644 --- a/package.json +++ b/package.json @@ -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" ],