From e701d8560935de88129c2bbd4a71f35deec2ed52 Mon Sep 17 00:00:00 2001 From: Arturas Molcanovas Date: Sun, 19 Nov 2017 00:34:46 +0000 Subject: [PATCH] iltorb tests --- types/iltorb/iltorb-tests.ts | 36 ++++++++++++++++++++++++++++++++++++ types/iltorb/index.d.ts | 30 ++++++++++++++++++++++++++++++ types/iltorb/tsconfig.json | 23 +++++++++++++++++++++++ types/iltorb/tslint.json | 3 +++ 4 files changed, 92 insertions(+) create mode 100644 types/iltorb/iltorb-tests.ts create mode 100644 types/iltorb/index.d.ts create mode 100644 types/iltorb/tsconfig.json create mode 100644 types/iltorb/tslint.json diff --git a/types/iltorb/iltorb-tests.ts b/types/iltorb/iltorb-tests.ts new file mode 100644 index 0000000000..4e425b36f6 --- /dev/null +++ b/types/iltorb/iltorb-tests.ts @@ -0,0 +1,36 @@ +import {createReadStream, createWriteStream} from 'fs'; +import * as br from 'iltorb'; + +const opts: br.BrotliEncodeParams = { + disable_literal_context_modeling: false, + lgblock: 0, + lgwin: 22, + mode: 0, + quality: 11, + size_hint: 0 +}; + +const onCompress = (err1: Error | null | undefined, compressed: Buffer) => { + br.decompress(compressed, (err2: Error | null | undefined, decompressed: Buffer) => { + console.log(decompressed.toString()); + }); +}; + +br.compress(Buffer.from('foo', 'utf8'), onCompress); + +br.compress(Buffer.from('foo', 'utf8'), opts, onCompress); + +createReadStream(__filename) + .pipe(br.compressStream()) + .pipe(createWriteStream('foo.ts')); + +createReadStream(__dirname) + .pipe(br.compressStream(opts)) + .pipe(createWriteStream('bar.ts')); + +createReadStream('bar.ts') + .pipe(br.decompressStream()) + .pipe(createWriteStream('qux.ts')); + +br.decompressSync(br.compressSync(Buffer.from('foo', 'utf8'))); +br.decompressSync(br.compressSync(Buffer.from('foo', 'utf8'), opts)); diff --git a/types/iltorb/index.d.ts b/types/iltorb/index.d.ts new file mode 100644 index 0000000000..ffec8bc6a6 --- /dev/null +++ b/types/iltorb/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for iltorb 2.0 +// Project: https://github.com/MayhemYDG/iltorb +// Definitions by: Arturas Molcanovas +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import { Transform } from 'stream'; + +export interface BrotliEncodeParams { + disable_literal_context_modeling?: boolean; + lgblock?: number; + lgwin?: number; + mode?: number; + quality?: number; + size_hint?: number; +} + +export type IltorbCallback = (err: Error | null | undefined, output: Buffer) => any; + +export function compress(buffer: Buffer, options: BrotliEncodeParams, callback: IltorbCallback): void; +export function compress(buffer: Buffer, callback: IltorbCallback): void; + +export function decompress(buffer: Buffer, callback: IltorbCallback): void; + +export function compressSync(buffer: Buffer, options?: BrotliEncodeParams): Buffer; +export function decompressSync(buffer: Buffer): Buffer; + +export function compressStream(options?: BrotliEncodeParams): Transform; +export function decompressStream(): Transform; diff --git a/types/iltorb/tsconfig.json b/types/iltorb/tsconfig.json new file mode 100644 index 0000000000..c12ff988ba --- /dev/null +++ b/types/iltorb/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es5" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "iltorb-tests.ts" + ] +} diff --git a/types/iltorb/tslint.json b/types/iltorb/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/iltorb/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}