mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
commit
8ceee56cb9
48
types/tar-fs/index.d.ts
vendored
Normal file
48
types/tar-fs/index.d.ts
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
// Type definitions for tar-fs 1.16
|
||||
// Project: https://github.com/mafintosh/tar-fs
|
||||
// Definitions by: Umoxfo <https://github.com/Umoxfo>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.6
|
||||
|
||||
// Imported from: https://github.com/soywiz/typescript-node-definitions/d.ts
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
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;
|
||||
}
|
||||
98
types/tar-fs/tar-fs-tests.ts
Normal file
98
types/tar-fs/tar-fs-tests.ts
Normal file
@ -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,
|
||||
});
|
||||
24
types/tar-fs/tsconfig.json
Normal file
24
types/tar-fs/tsconfig.json
Normal file
@ -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"
|
||||
]
|
||||
}
|
||||
3
types/tar-fs/tslint.json
Normal file
3
types/tar-fs/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user