|
| 1 | +// Type definitions for bufferstream v0.6.2 |
| 2 | +// Project: https://github.com/dodo/node-bufferstream |
| 3 | +// Definitions by: Bart van der Schoor <https://github.com/Bartvds> |
| 4 | +// Definitions: https://github.com/borisyankov/DefinitelyTyped |
| 5 | + |
| 6 | +/// <reference path="../node/node.d.ts" /> |
| 7 | + |
| 8 | +declare module 'bufferstream' { |
| 9 | + import stream = require('stream'); |
| 10 | + |
| 11 | + export = BufferStream; |
| 12 | + |
| 13 | + class BufferStream extends stream.Duplex { |
| 14 | + constructor(options?: BufferStream.Opts); |
| 15 | + |
| 16 | + /* |
| 17 | + different buffer behaviors can be triggered by size: |
| 18 | +
|
| 19 | + none when output drains, bufferstream drains too |
| 20 | + flexible buffers everthing that it gets and not piping out |
| 21 | + <number> TODO buffer has given size. buffers everthing until buffer is full. when buffer is full then the stream will drain |
| 22 | + */ |
| 23 | + setSize(size: string): void; // can be one of ['none', 'flexible', <number>] |
| 24 | + setSize(size: number): void; // can be one of ['none', 'flexible', <number>] |
| 25 | + /* |
| 26 | + enables stream buffering default |
| 27 | + */ |
| 28 | + enable(): void; |
| 29 | + /* |
| 30 | + flushes buffer and disables stream buffering. BufferStream now pipes all data as long as the output accepting data. when the output is draining BufferStream will buffer all input temporary. |
| 31 | +
|
| 32 | + token[s] buffer splitters (should be String or Buffer) |
| 33 | +
|
| 34 | + disables given tokens. wont flush until no splitter tokens are left. |
| 35 | + */ |
| 36 | + disable(): void; |
| 37 | + disable(token: string, ...tokens: string[]): void; |
| 38 | + disable(tokens: string[]): void; // Array |
| 39 | + disable(token: Buffer, ...tokens: Buffer[]): void; |
| 40 | + disable(tokens: Buffer[]): void; // Array |
| 41 | + /* |
| 42 | + each time BufferStream finds a splitter token in the input data it will emit a split event. this also works for binary data. |
| 43 | +
|
| 44 | + token[s] buffer splitters (should be String or Buffer) |
| 45 | + */ |
| 46 | + split(token: string, ...tokens: string[]): void; |
| 47 | + split(tokens: string[]): void; // Array |
| 48 | + split(token: Buffer, ...tokens: Buffer[]): void; |
| 49 | + split(tokens: Buffer[]): void; // Array |
| 50 | + /* |
| 51 | + returns Buffer. |
| 52 | + */ |
| 53 | + getBuffer(): Buffer; |
| 54 | + /* |
| 55 | + returns Buffer. |
| 56 | + */ |
| 57 | + buffer: Buffer; |
| 58 | + /* |
| 59 | + shortcut for buffer.toString() |
| 60 | + */ |
| 61 | + toString(): string; |
| 62 | + /* |
| 63 | + shortcut for buffer.length |
| 64 | + */ |
| 65 | + length: number; |
| 66 | + } |
| 67 | + module BufferStream { |
| 68 | + |
| 69 | + export interface Opts { |
| 70 | + /* |
| 71 | + default encoding for writing strings |
| 72 | + */ |
| 73 | + encoding?: string; |
| 74 | + /* |
| 75 | + if true and the source is a child_process the stream will block the entire process (timeouts wont work anymore, but splitting and listening on data still works, because they work sync) |
| 76 | + */ |
| 77 | + blocking?: boolean; |
| 78 | + /* |
| 79 | + defines buffer level or sets buffer to given size (see ↓setSize for more) |
| 80 | + */ |
| 81 | + size?: any; |
| 82 | + /* |
| 83 | + immediately call disable |
| 84 | + */ |
| 85 | + disabled?: boolean; |
| 86 | + /* |
| 87 | + short form for: |
| 88 | + split(token, function (chunk) {emit('data', chunk)}) |
| 89 | + */ |
| 90 | + // String or Buffer |
| 91 | + split?: any; |
| 92 | + } |
| 93 | + export var fn: {warn: boolean}; |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +declare module 'bufferstream/postbuffer' { |
| 98 | + import http = require('http'); |
| 99 | + import BufferStream = require('bufferstream'); |
| 100 | + |
| 101 | + class PostBuffer extends BufferStream { |
| 102 | + /* |
| 103 | + for if you want to get all the post data from a http server request and do some db reqeust before. |
| 104 | +
|
| 105 | + http client buffer |
| 106 | + */ |
| 107 | + constructor(req: http.ServerRequest); |
| 108 | + /* |
| 109 | + set a callback to get all post data from a http server request |
| 110 | + */ |
| 111 | + onEnd(callback: (data: any) => void): void; |
| 112 | + /* |
| 113 | + pumps data into another stream to allow incoming streams given options will be passed to Stream.pipe |
| 114 | + */ |
| 115 | + pipe(stream: NodeJS.WritableStream, options?: BufferStream.Opts): NodeJS.ReadableStream; |
| 116 | + } |
| 117 | + |
| 118 | + export = PostBuffer; |
| 119 | +} |
0 commit comments