mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-12 14:30:06 +00:00
129
types/lzma-native/index.d.ts
vendored
Normal file
129
types/lzma-native/index.d.ts
vendored
Normal file
@@ -0,0 +1,129 @@
|
||||
// Type definitions for lzma-native 4.0
|
||||
// Project: https://github.com/addaleax/lzma-native
|
||||
// Definitions by: Evan Cameron <https://github.com/leshow>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
/// <reference types="node" />
|
||||
|
||||
import { Stream } from "stream";
|
||||
export interface LzmaOptions {
|
||||
synchronous?: boolean;
|
||||
bufsize?: number;
|
||||
memlimit?: number;
|
||||
check?: Check;
|
||||
preset?: Preset;
|
||||
flags?:
|
||||
| "TELL_NO_CHECK"
|
||||
| "TELL_UNSUPPORTED_CHECK"
|
||||
| "TELL_ANY_CHECK"
|
||||
| "CONCATENATED";
|
||||
threads?: number;
|
||||
blockSize?: number;
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
export type Check =
|
||||
| "CHECK_CRC32"
|
||||
| "CHECK_CRC64"
|
||||
| "CHECK_NONE"
|
||||
| "CHECK_SHA256";
|
||||
|
||||
export type Coders =
|
||||
| "easyEncoder"
|
||||
| "aloneDecoder"
|
||||
| "rawEncoder"
|
||||
| "autoDecoder"
|
||||
| "aloneEncoder"
|
||||
| "streamEncoder"
|
||||
| "streamDecoder";
|
||||
|
||||
export type Preset = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
||||
|
||||
export interface FileOptions {
|
||||
fileSize: number;
|
||||
memlimit?: number;
|
||||
read: (
|
||||
count: number,
|
||||
offset: number,
|
||||
cb: (err: any, buffer: Buffer) => void
|
||||
) => void;
|
||||
}
|
||||
|
||||
export interface StreamInfo {
|
||||
streamPadding: number;
|
||||
memlimit: number;
|
||||
streams: number;
|
||||
blocks: number;
|
||||
fileSize: number;
|
||||
uncompressedSize: number;
|
||||
checks: number;
|
||||
}
|
||||
|
||||
export function createStream(
|
||||
coder: Coders,
|
||||
options?: LzmaOptions
|
||||
): JSLzmaStream;
|
||||
|
||||
export function createCompressor(options?: LzmaOptions): JSLzmaStream;
|
||||
export function createDecompressor(options?: LzmaOptions): JSLzmaStream;
|
||||
export function crc32(
|
||||
input: string,
|
||||
encoding?: string,
|
||||
previous?: number
|
||||
): string;
|
||||
export function isXZ(buf: Buffer | string): boolean;
|
||||
export function versionString(): string;
|
||||
export function versionNumber(): number;
|
||||
export function checkSize(check: Check): number;
|
||||
export function easyDecoderMemusage(preset: Preset): number;
|
||||
export function easyEncoderMemusage(preset: Preset): number;
|
||||
export function rawDecoderMemusage(preset: Preset): number;
|
||||
export function rawEncoderMemusage(preset: Preset): number;
|
||||
|
||||
export function Compressor(
|
||||
preset?: Preset,
|
||||
options?: LzmaOptions
|
||||
): JSLzmaStream;
|
||||
export function Decompressor(options?: LzmaOptions): JSLzmaStream;
|
||||
|
||||
export function parseFileIndex(
|
||||
options: FileOptions,
|
||||
callback?: (err: any, info?: StreamInfo) => void
|
||||
): void;
|
||||
export function parseFileIndexFD(
|
||||
fileDescriptor: number,
|
||||
callback?: (err: any, info?: StreamInfo) => void
|
||||
): void;
|
||||
|
||||
export function compress(
|
||||
buf: Buffer | string,
|
||||
options?: LzmaOptions | Preset,
|
||||
on_finish?: (result: Buffer) => void
|
||||
): void;
|
||||
export function decompress(
|
||||
buf: Buffer | string,
|
||||
options?: LzmaOptions | Preset,
|
||||
on_finish?: (result: Buffer) => void
|
||||
): void;
|
||||
export function LZMA(): {
|
||||
compress(
|
||||
buf: Buffer | string,
|
||||
mode: Preset,
|
||||
on_finish: (result: Buffer) => void,
|
||||
on_progress?: (progress: number) => void
|
||||
): void;
|
||||
decompress(
|
||||
buf: Buffer | string,
|
||||
on_finish: (result: Buffer) => void,
|
||||
on_progress?: (progress: number) => void
|
||||
): void;
|
||||
};
|
||||
|
||||
export class JSLzmaStream extends Stream.Transform {
|
||||
constructor(nativeStream: Stream, options: LzmaOptions);
|
||||
bufsize(): number;
|
||||
bufsize(size: number): void;
|
||||
totalInt(): number;
|
||||
totalOut(): number;
|
||||
cleanUp(): void;
|
||||
}
|
||||
55
types/lzma-native/lzma-native-tests.ts
Normal file
55
types/lzma-native/lzma-native-tests.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import * as lzma from "lzma-native";
|
||||
import * as fs from "fs";
|
||||
|
||||
const compressor = lzma.createCompressor();
|
||||
const input = fs.createReadStream("tsconfig.json");
|
||||
const output = fs.createWriteStream("tsconfig.json.xz");
|
||||
|
||||
input.pipe(compressor).pipe(output);
|
||||
|
||||
lzma.compress("Banana", undefined, result => {
|
||||
console.log(result); // <Buffer fd 37 7a 58 5a 00 00 01 69 22 de 36 02 00 21 ...>
|
||||
});
|
||||
|
||||
lzma.compress("Bananas", 6, result => {
|
||||
lzma.decompress(result, undefined, decompressedResult => {
|
||||
console.log(decompressedResult.toString() === "Bananas");
|
||||
});
|
||||
});
|
||||
|
||||
lzma.LZMA().compress("Bananas", 4, result => {
|
||||
lzma.LZMA().decompress(result, decompressedResult => {
|
||||
console.log("Bananas" === decompressedResult.toString());
|
||||
});
|
||||
});
|
||||
|
||||
const comp = lzma.Compressor();
|
||||
|
||||
process.stdin.pipe(comp).pipe(process.stdout);
|
||||
lzma.crc32("Banana"); // => 69690105
|
||||
lzma.checkSize("CHECK_SHA256"); // => 16
|
||||
lzma.checkSize("CHECK_CRC32"); // => 4
|
||||
lzma.easyDecoderMemusage(6); // => 8454192
|
||||
lzma.easyEncoderMemusage(6); // => 97620499
|
||||
lzma.versionString(); // => '5.2.3'
|
||||
lzma.versionNumber(); // => 50020012
|
||||
lzma.isXZ("Banana"); // => false
|
||||
|
||||
fs.open("test/hamlet.txt.xz", "r", (err: any, fd: number) => {
|
||||
if (err) return;
|
||||
// handle error
|
||||
lzma.parseFileIndexFD(fd, (err, info) => {
|
||||
// handle error
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
// do something with e.g. info.uncompressedSize
|
||||
|
||||
fs.close(fd, (err: any) => {
|
||||
/* handle error */
|
||||
if (err) {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
16
types/lzma-native/tsconfig.json
Normal file
16
types/lzma-native/tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"noImplicitThis": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": ["index.d.ts", "lzma-native-tests.ts"]
|
||||
}
|
||||
1
types/lzma-native/tslint.json
Normal file
1
types/lzma-native/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user