mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-19 13:32:17 +08:00
Merge pull request #14617 from Jason3S/master
Add types for stream-buffers
This commit is contained in:
40
stream-buffers/index.d.ts
vendored
Normal file
40
stream-buffers/index.d.ts
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
// Type definitions for stream-buffers 3.0
|
||||
// Project: https://github.com/samcday/node-stream-buffer#readme
|
||||
// Definitions by: Jason Dent <https://github.com/Jason3S>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
import * as stream from 'stream';
|
||||
|
||||
export interface WritableStreamBufferOptions extends stream.WritableOptions {
|
||||
initialSize?: number;
|
||||
incrementAmount?: number;
|
||||
}
|
||||
|
||||
export declare class WritableStreamBuffer extends stream.Writable {
|
||||
constructor(options?: WritableStreamBufferOptions);
|
||||
size(): number;
|
||||
maxSize(): number;
|
||||
getContents(length?: number): any;
|
||||
getContentsAsString(encoding?: string, length?: number): string;
|
||||
}
|
||||
|
||||
export interface ReadableStreamBufferOptions extends stream.ReadableOptions {
|
||||
frequency?: number;
|
||||
chunkSize?: number;
|
||||
initialSize?: number;
|
||||
incrementAmount?: number;
|
||||
}
|
||||
|
||||
export declare class ReadableStreamBuffer extends stream.Readable {
|
||||
constructor(options?: ReadableStreamBufferOptions);
|
||||
put(data: string | Buffer, encoding?: string): void;
|
||||
stop(): void;
|
||||
size(): number;
|
||||
maxSize(): number;
|
||||
}
|
||||
|
||||
export declare const DEFAULT_INITIAL_SIZE: number;
|
||||
export declare const DEFAULT_INCREMENT_AMOUNT: number;
|
||||
export declare const DEFAULT_FREQUENCY: number;
|
||||
export declare const DEFAULT_CHUNK_SIZE: number;
|
||||
48
stream-buffers/stream-buffers-tests.ts
Normal file
48
stream-buffers/stream-buffers-tests.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import * as streamBuffers from 'stream-buffers';
|
||||
|
||||
// The following are examples from README.md
|
||||
// https://github.com/samcday/node-stream-buffer
|
||||
|
||||
var myWritableStreamBuffer = new streamBuffers.WritableStreamBuffer({
|
||||
initialSize: (100 * 1024), // start at 100 kilobytes.
|
||||
incrementAmount: (10 * 1024) // grow by 10 kilobytes each time buffer overflows.
|
||||
});
|
||||
|
||||
var a = streamBuffers.DEFAULT_INITIAL_SIZE; // (8 * 1024)
|
||||
var b = streamBuffers.DEFAULT_INCREMENT_AMOUNT; // (8 * 1024)
|
||||
var c = streamBuffers.DEFAULT_CHUNK_SIZE; // (1024)
|
||||
var d = streamBuffers.DEFAULT_FREQUENCY; // (1)
|
||||
|
||||
const buffer = new Buffer('ASDF');
|
||||
myWritableStreamBuffer.write('ASDF');
|
||||
myWritableStreamBuffer.write(buffer);
|
||||
myWritableStreamBuffer.size();
|
||||
myWritableStreamBuffer.maxSize();
|
||||
|
||||
// Gets all held data as a Buffer.
|
||||
myWritableStreamBuffer.getContents();
|
||||
|
||||
// Gets all held data as a utf8 string.
|
||||
myWritableStreamBuffer.getContentsAsString('utf8');
|
||||
|
||||
// Gets first 5 bytes as a Buffer.
|
||||
myWritableStreamBuffer.getContents(5);
|
||||
|
||||
// Gets first 5 bytes as a utf8 string.
|
||||
myWritableStreamBuffer.getContentsAsString('utf8', 5);
|
||||
|
||||
var myReadableStreamBuffer = new streamBuffers.ReadableStreamBuffer({
|
||||
frequency: 10, // in milliseconds.
|
||||
chunkSize: 2048 // in bytes.
|
||||
});
|
||||
|
||||
myReadableStreamBuffer.put('A String', 'utf8');
|
||||
myReadableStreamBuffer.put(buffer);
|
||||
|
||||
myReadableStreamBuffer.on('data', function(data) {
|
||||
// streams1.x style data
|
||||
// assert.isTrue(data instanceof Buffer);
|
||||
});
|
||||
|
||||
myReadableStreamBuffer.put('the last data this stream will ever see');
|
||||
myReadableStreamBuffer.stop();
|
||||
22
stream-buffers/tsconfig.json
Normal file
22
stream-buffers/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"stream-buffers-tests.ts"
|
||||
]
|
||||
}
|
||||
1
stream-buffers/tslint.json
Normal file
1
stream-buffers/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Reference in New Issue
Block a user