add zopfli tests

This commit is contained in:
Arturas 2018-06-25 23:11:54 +01:00
parent 9752e82a3d
commit e9923e6940
4 changed files with 144 additions and 0 deletions

69
types/node-zopfli/index.d.ts vendored Normal file
View File

@ -0,0 +1,69 @@
// Type definitions for node-zopfli 2.0
// Project: https://github.com/pierreinglebert/node-zopfli
// Definitions by: Alorel <https://github.com/Alorel>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
import { Transform } from 'stream';
declare class Zopfli extends Transform {
constructor(format?: Zopfli.Format, options?: Zopfli.Options);
static createGzip(options?: Zopfli.Options): Zopfli;
static createDeflate(options?: Zopfli.Options): Zopfli;
static createZlib(options?: Zopfli.Options): Zopfli;
static gzipSync(options?: Zopfli.Options): Buffer;
static deflateSync(options?: Zopfli.Options): Buffer;
static zlibSync(options?: Zopfli.Options): Buffer;
static deflate(input: Buffer, options: Zopfli.Options, cb: (err: Error, out: Buffer) => void): void;
static deflate(input: Buffer, cb: (err: Error, out: Buffer) => void): void;
static deflate(input: Buffer, options?: Zopfli.Options): Promise<Buffer>;
static gzip(input: Buffer, options: Zopfli.Options, cb: (err: Error, out: Buffer) => void): void;
static gzip(input: Buffer, cb: (err: Error, out: Buffer) => void): void;
static gzip(input: Buffer, options?: Zopfli.Options): Promise<Buffer>;
static zlib(input: Buffer, options: Zopfli.Options, cb: (err: Error, out: Buffer) => void): void;
static zlib(input: Buffer, cb: (err: Error, out: Buffer) => void): void;
static zlib(input: Buffer, options?: Zopfli.Options): Promise<Buffer>;
static compress(input: Buffer, format: Zopfli.Format, options: Zopfli.Options, cb: (err: Error, out: Buffer) => void): void;
static compress(input: Buffer, format: Zopfli.Format, cb: (err: Error, out: Buffer) => void): void;
static compress(input: Buffer, format: Zopfli.Format, options?: Zopfli.Options): Promise<Buffer>;
}
declare namespace Zopfli {
type Format = 'deflate' | 'gzip' | 'zlib';
interface Options {
verbose?: boolean;
verbose_more?: boolean;
/**
* Maximum amount of times to rerun forward and backward pass to optimize LZ77 compression cost.
* Good values: 10, 15 for small files, 5 for files over several MB in size or it will be too slow.
*/
numiterations?: number;
/**
* If true, splits the data in multiple deflate blocks with optimal choice for the block boundaries.
* Block splitting gives better compression.
*/
blocksplitting?: boolean;
/**
* If true, chooses the optimal block split points only after doing the iterative LZ77 compression.
* If false, chooses the block split points first, then does iterative LZ77 on each individual block.
* Depending on the file, either first or last gives the best compression.
*/
blocksplittinglast?: boolean;
/**
* Maximum amount of blocks to split into (0 for unlimited,
* but this can give extreme results that hurt compression on some files).
*/
blocksplittingmax?: number;
}
}
export = Zopfli;

View File

@ -0,0 +1,51 @@
import * as Zopfli from 'node-zopfli';
import * as fs from 'fs';
const opts: Zopfli.Options = {
verbose: true,
numiterations: 1
};
let input: Buffer = Buffer.from('foo');
const read = fs.createReadStream('foo');
const write = fs.createWriteStream('foo');
function cb(e: Error, b: Buffer): void {}
function then(b: Buffer): void {}
Zopfli.zlib(input, cb);
Zopfli.zlib(input, opts, cb);
Zopfli.zlib(input, opts).then(then);
Zopfli.zlib(input).then(then);
Zopfli.gzip(input, cb);
Zopfli.gzip(input, opts, cb);
Zopfli.gzip(input, opts).then(then);
Zopfli.gzip(input).then(then);
Zopfli.deflate(input, cb);
Zopfli.deflate(input, opts, cb);
Zopfli.deflate(input, opts).then(then);
Zopfli.deflate(input).then(then);
Zopfli.compress(input, 'zlib', cb);
Zopfli.compress(input, 'zlib', opts, cb);
Zopfli.compress(input, 'zlib', opts).then(then);
Zopfli.compress(input, 'zlib').then(then);
input = Zopfli.gzipSync();
input = Zopfli.gzipSync(opts);
input = Zopfli.deflateSync();
input = Zopfli.deflateSync(opts);
input = Zopfli.zlibSync();
input = Zopfli.zlibSync(opts);
read.pipe(Zopfli.createGzip()).pipe(write);
read.pipe(Zopfli.createGzip(opts)).pipe(write);
read.pipe(Zopfli.createDeflate()).pipe(write);
read.pipe(Zopfli.createDeflate(opts)).pipe(write);
read.pipe(Zopfli.createZlib()).pipe(write);
read.pipe(Zopfli.createZlib(opts)).pipe(write);

View File

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

View File

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