mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add definitions for tar-stream
This commit is contained in:
parent
52aaa6bc5c
commit
58dd75a89d
42
types/tar-stream/index.d.ts
vendored
Normal file
42
types/tar-stream/index.d.ts
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// Type definitions for tar-stream 1.6
|
||||
// Project: https://github.com/mafintosh/tar-stream
|
||||
// Definitions by: Guy Lichtman <https://github.com/glicht>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.6
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import stream = require('stream');
|
||||
|
||||
export type Callback = (err?: Error | null) => any;
|
||||
|
||||
// see https://github.com/mafintosh/tar-stream/blob/master/headers.js
|
||||
export interface Headers {
|
||||
name: string;
|
||||
mode?: number;
|
||||
uid?: number;
|
||||
gid?: number;
|
||||
size?: number;
|
||||
mtime?: Date;
|
||||
linkname?: string | null;
|
||||
type?: 'file' | 'link' | 'symlink' | 'character-device' | 'block-device' | 'directory' | 'fifo' |
|
||||
'contiguous-file' | 'pax-header' | 'pax-global-header' | 'gnu-long-link-path' | 'gnu-long-path' | null;
|
||||
uname?: string;
|
||||
gname?: string;
|
||||
devmajor?: number;
|
||||
devminor?: number;
|
||||
}
|
||||
|
||||
export interface Pack extends stream.Readable {
|
||||
entry(headers: Headers, buffer?: string | Buffer | Callback, callback?: Callback): stream.Writable;
|
||||
finalize(): void;
|
||||
}
|
||||
|
||||
export interface Extract extends stream.Writable {
|
||||
on(event: string, listener: (...args: any[]) => void): this;
|
||||
on(event: "entry", listener: (headers: Headers, stream: stream.PassThrough, next: () => void ) => void): this;
|
||||
}
|
||||
|
||||
export function extract(opts?: stream.WritableOptions): stream.Writable;
|
||||
|
||||
export function pack(opts?: stream.ReadableOptions): Pack;
|
||||
44
types/tar-stream/tar-stream-tests.ts
Normal file
44
types/tar-stream/tar-stream-tests.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import tar = require('tar-stream');
|
||||
|
||||
const pack = tar.pack();
|
||||
|
||||
// add a file called my-test.txt with the content "Hello World!"
|
||||
pack.entry({ name: 'my-test1.txt' }, 'Hello World!');
|
||||
|
||||
// add a file called my-stream-test.txt from a stream
|
||||
const entry = pack.entry({ name: 'my-test2.txt', size: 11 }, (err) => {
|
||||
// the stream was added
|
||||
// no more entries
|
||||
pack.finalize();
|
||||
});
|
||||
|
||||
entry.write('hello');
|
||||
entry.write(' ');
|
||||
entry.write('world');
|
||||
entry.end();
|
||||
|
||||
const extract = tar.extract();
|
||||
|
||||
const entries: any = {};
|
||||
|
||||
extract.on('entry', (header, stream, next) => {
|
||||
// header is the tar header
|
||||
// stream is the content body (might be an empty stream)
|
||||
// call next when you are done with this entry
|
||||
entries[header.name] = true;
|
||||
stream.on('end', () => {
|
||||
next();
|
||||
});
|
||||
|
||||
stream.resume(); // just auto drain the stream
|
||||
});
|
||||
|
||||
extract.on('finish', () => {
|
||||
// all entries read
|
||||
console.assert(entries['my-test1.txt'], "missing entry");
|
||||
console.assert(entries['my-test2.txt'], "missing entry");
|
||||
console.log("Found all entries in extract");
|
||||
});
|
||||
|
||||
// pipe the pack stream
|
||||
pack.pipe(extract);
|
||||
23
types/tar-stream/tsconfig.json
Normal file
23
types/tar-stream/tsconfig.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"tar-stream-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/tar-stream/tslint.json
Normal file
1
types/tar-stream/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user