diff --git a/types/tar-fs/index.d.ts b/types/tar-fs/index.d.ts new file mode 100644 index 0000000000..07c02bab4b --- /dev/null +++ b/types/tar-fs/index.d.ts @@ -0,0 +1,48 @@ +// Type definitions for tar-fs 1.16 +// Project: https://github.com/mafintosh/tar-fs +// Definitions by: Umoxfo +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.6 + +// Imported from: https://github.com/soywiz/typescript-node-definitions/d.ts + +/// + +import fs = require("fs"); + +export function pack(cwd: string, opts?: PackOptions): any; +export function extract(cwd: string, opts?: ExtractOptions): any; + +export interface Options { + ignore?: (name: string) => boolean; + filter?: (name: string) => boolean; + map?: (header: Headers) => Headers; + mapStream?: (fileStream: fs.ReadStream, header: Headers) => fs.ReadStream; + strict?: boolean; +} + +export interface PackOptions extends Options { + entries?: string[]; + dereference?: boolean; + finalize?: boolean; + finish?: (pack: any) => void; +} + +export interface ExtractOptions extends Options { + ignore?: (name: string, header?: Headers) => boolean; + filter?: (name: string, header?: Headers) => boolean; + dmode?: number; + fmode?: number; + readable?: boolean; + writable?: boolean; +} + +export interface Headers { + name: string; + mode: number; + mtime: Date; + size: number; + type: "file" | "directory" | "symlink"; + uid: number; + gid: number; +} diff --git a/types/tar-fs/tar-fs-tests.ts b/types/tar-fs/tar-fs-tests.ts new file mode 100644 index 0000000000..a419f907cb --- /dev/null +++ b/types/tar-fs/tar-fs-tests.ts @@ -0,0 +1,98 @@ +import tar = require("tar-fs"); +import fs = require("fs"); +import path = require("path"); +import stream = require("stream"); + +/* + * Default test + */ +// packing a directory +tar.pack('./my-directory').pipe(fs.createWriteStream('my-tarball.tar')); + +// extracting a directory +fs.createReadStream('my-other-tarball.tar').pipe(tar.extract('./my-other-directory')); + +/* + * Ignore various files + */ +tar.pack('./my-directory', { + ignore: (name) => { + return path.extname(name) === '.bin'; // ignore .bin files when packing + } +}); + +tar.extract('./my-other-directory', { + ignore: (name) => { + return path.extname(name) === '.bin'; // ignore .bin files inside the tarball when extracing + } +}); + +tar.extract('./my-other-other-directory', { + ignore: (_, header) => { + // pass files & directories, ignore e.g. symlinks + return header.type !== 'file' && header.type !== 'directory'; + } +}); + +/* + * Specify which entries to pack + */ +tar.pack('./my-directory', { + entries: ['file1', 'subdir/file2'], // only the specific entries will be packed +}); + +/* + * Modify the headers by map + */ +tar.pack('./my-directory', { + map: (header) => { + header.name = 'prefixed/' + header.name; + return header; + } +}); + +tar.extract('./my-directory', { + map: (header) => { + header.name = 'another-prefix/' + header.name; + return header; + } +}); + +/* + * Modify the headers by mapStream + */ +tar.pack('./my-directory', { + mapStream: (fileStream, header) => { + if (path.extname(header.name) === '.js') { + return fileStream; + } + return fileStream; + } +}); + +tar.extract('./my-directory', { + mapStream: (fileStream, header) => { + if (path.extname(header.name) === '.js') { + return fileStream; + } + return fileStream; + } +}); + +/* + * The corresponding modes + */ +tar.extract('./my-directory', { + dmode: parseInt("555", 8), + fmode: parseInt("444", 8), + readable: true, + writable: true, +}); + +/* + * The other options + */ +tar.pack('./my-directory', { + strict: false, + dereference: true, +}); diff --git a/types/tar-fs/tsconfig.json b/types/tar-fs/tsconfig.json new file mode 100644 index 0000000000..c7f77701e8 --- /dev/null +++ b/types/tar-fs/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true + }, + "files": [ + "index.d.ts", + "tar-fs-tests.ts" + ] +} \ No newline at end of file diff --git a/types/tar-fs/tslint.json b/types/tar-fs/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/tar-fs/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file