From 38e351fa5aafc96d9e4eeecd56fbad771220ba51 Mon Sep 17 00:00:00 2001 From: crispybee Date: Sun, 27 Aug 2017 23:25:45 +0200 Subject: [PATCH] Add typings for read-chunk --- types/read-chunk/index.d.ts | 29 ++++++++++++++++++++++++++++ types/read-chunk/read-chunk-tests.ts | 9 +++++++++ types/read-chunk/tsconfig.json | 22 +++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 types/read-chunk/index.d.ts create mode 100644 types/read-chunk/read-chunk-tests.ts create mode 100644 types/read-chunk/tsconfig.json diff --git a/types/read-chunk/index.d.ts b/types/read-chunk/index.d.ts new file mode 100644 index 0000000000..d11a7a334b --- /dev/null +++ b/types/read-chunk/index.d.ts @@ -0,0 +1,29 @@ +// Type definitions for read-chunk v2.1.0 +// Project: https://github.com/sindresorhus/read-chunk +// Definitions by: crispybee +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +export = ReadChunk; + + /** + * Asynchronous: Reads a chunk from a file. Returns a Promise. + * @param {string} filePath The path to the file. + * @param {number} startingPosition Position to start reading. + * @param {number} length Number of bytes to read. + * @return {Promise} Returns a Promise. + */ +declare function ReadChunk(filePath: string, startingPosition: number, length: number): Promise; + +declare namespace ReadChunk { + /** + * Synchronous: Reads a chunk from a file. Returns a Buffer. + * @param {string} filePath The path to the file. + * @param {number} startingPosition Position to start reading. + * @param {number} length Number of bytes to read. + * @return {Buffer} Returns a Buffer. + */ + function sync(filePath: string, startingPosition: number, length: number): Buffer; +} + diff --git a/types/read-chunk/read-chunk-tests.ts b/types/read-chunk/read-chunk-tests.ts new file mode 100644 index 0000000000..187d1a02b1 --- /dev/null +++ b/types/read-chunk/read-chunk-tests.ts @@ -0,0 +1,9 @@ +import readChunk = require('read-chunk'); + +let chunk: Buffer = readChunk.sync('foo.txt', 1, 3); + +readChunk('foo.txt', 1, 3).then(value => { + console.log(value); +}).catch(error => { + console.log(error); +}); diff --git a/types/read-chunk/tsconfig.json b/types/read-chunk/tsconfig.json new file mode 100644 index 0000000000..a26a5e2143 --- /dev/null +++ b/types/read-chunk/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "read-chunk-tests.ts" + ] +} \ No newline at end of file