add @types/tar-js (#50099)

* add @types/tar-js

* fix Definitions by

* add(tar-js): clear api

* add(tar-js): add test
This commit is contained in:
Narazaka
2020-12-15 05:36:48 +09:00
committed by GitHub
parent 726796caa6
commit a46cca4ced
4 changed files with 71 additions and 0 deletions

26
types/tar-js/index.d.ts vendored Normal file
View File

@@ -0,0 +1,26 @@
// Type definitions for tar-js 0.3
// Project: http://github.com/beatgammit/tar-js
// Definitions by: Narazaka <https://github.com/Narazaka>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class Tar {
written: number;
out: Uint8Array;
constructor(recordsPerBlock?: number);
append(filepath: string, input: string | Uint8Array, opts?: Tar.TarOptions, callback?: (out: Uint8Array) => any): Uint8Array;
append(filepath: string, input: string | Uint8Array, callback?: (out: Uint8Array) => any): Uint8Array;
clear(): void;
}
declare namespace Tar {
interface TarOptions {
mode?: number;
mtime?: number;
uid?: number;
gid?: number;
owner?: string;
group?: string;
}
}
export = Tar;

View File

@@ -0,0 +1,21 @@
/// <reference types="node" />
import * as Tar from "tar-js";
const tar = new Tar();
console.log(tar.written === 0);
const out: Uint8Array = tar.out;
console.log(out);
tar.append("foo.txt", "foo");
tar.append("bar.txt", "bar", {mode: 0o755, mtime: 123, uid: 0, gid: 0, owner: "owner", group: "group"});
tar.append("baz.txt", "baz", (out1) => {
const out2: Uint8Array = out1;
console.log(out2);
});
tar.append("hoge.txt", "hoge", {mode: 0o755, mtime: 123, uid: 0, gid: 0, owner: "owner", group: "group"}, (out1) => {
const out2: Uint8Array = out1;
console.log(out2);
});
tar.append("fuga.txt", new Uint8Array(Buffer.from("fuga")));
tar.clear();
const tar2 = new Tar(1024);
console.log(tar2);

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"tar-js-tests.ts"
]
}

1
types/tar-js/tslint.json Normal file
View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }