snappy: create typedefs

This commit is contained in:
Francis Gulotta
2018-08-17 16:43:20 -07:00
parent 64b9574a76
commit b62cd17d4d
4 changed files with 83 additions and 0 deletions

24
types/snappy/index.d.ts vendored Normal file
View File

@@ -0,0 +1,24 @@
// Type definitions for snappy 6.0
// Project: https://github.com/kesla/node-snappy
// Definitions by: Francis Gulotta <https://github.com/reconbot>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node"/>
export interface SnappyDecompressOpts {
asBuffer: boolean;
}
export type bufferCallback = (err: Error | null, data: Buffer) => void;
export type bufferOrStringCallback = (err: Error | null, data: Buffer|string) => void;
export type booleanCallback = (err: Error | null, data: boolean) => void;
export function compress(buffer: Buffer|string, callback: bufferCallback): void;
export function compressSync(buffer: Buffer|string): Buffer;
export function uncompress(buffer: Buffer, callback: bufferCallback): void;
export function uncompress(buffer: Buffer, options: SnappyDecompressOpts, callback: bufferOrStringCallback): void;
export function uncompressSync(buffer: Buffer): Buffer;
export function uncompressSync(buffer: Buffer, options: SnappyDecompressOpts): Buffer|string;
export function isValidCompressed(buffer: Buffer, callback: booleanCallback): void;
export function isValidCompressedSync(buffer: Buffer): boolean;

View File

@@ -0,0 +1,35 @@
import * as snappy from 'snappy';
snappy.compress('beep boop', (err, compressed) => {
if (err) {
throw err;
}
console.log(compressed.slice(0, 1));
});
const data = snappy.compressSync('beep boop');
const otherData = snappy.compressSync(Buffer.from('beep boop'));
snappy.uncompress(data, (err, data) => {
if (err) {
throw err;
}
console.log(data.toString('UTF8'));
});
snappy.uncompress(otherData, { asBuffer: false }, (err, original) => {
if (err) {
throw err;
}
console.log('the original String', original);
});
snappy.uncompressSync(data);
snappy.uncompressSync(data, { asBuffer: false });
snappy.isValidCompressed(data, (err, valid) => {
if (err) {
throw err;
}
console.log(valid);
});
if (snappy.isValidCompressedSync(data)) {
console.log('valid!');
}

View File

@@ -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",
"snappy-tests.ts"
]
}

1
types/snappy/tslint.json Normal file
View File

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