Skip to content

Commit 8366381

Browse files
committed
Merge pull request DefinitelyTyped#2374 from Bartvds/def/bufferstream
added some buffer/stream modules
2 parents 62ba550 + bd3b137 commit 8366381

9 files changed

+226
-1
lines changed

JSONStream/JSONStream-tests.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="JSONStream.d.ts" />
2+
3+
import json = require('JSONStream');
4+
5+
var read: NodeJS.ReadableStream;
6+
var write: NodeJS.WritableStream;
7+
8+
read = read.pipe(json.parse('*'));
9+
read = read.pipe(json.parse(['foo/*', 'bar/*']));
10+
11+
read = json.stringify();
12+
read = json.stringify('{', ',', '}');
13+
14+
read = json.stringifyObject();
15+
read = json.stringifyObject('{', ',', '}');

JSONStream/JSONStream.d.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Type definitions for JSONStream v0.8.0
2+
// Project: http://github.com/dominictarr/JSONStream
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 'JSONStream' {
9+
10+
export interface Options {
11+
recurse: boolean;
12+
}
13+
14+
export function parse(pattern: any): NodeJS.ReadWriteStream;
15+
export function parse(patterns: any[]): NodeJS.ReadWriteStream;
16+
17+
export function stringify(): NodeJS.ReadWriteStream;
18+
export function stringify(open: string, sep: string, close: string): NodeJS.ReadWriteStream;
19+
20+
export function stringifyObject(): NodeJS.ReadWriteStream;
21+
export function stringifyObject(open: string, sep: string, close: string): NodeJS.ReadWriteStream;
22+
}

buffer-equal/buffer-equal.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Type definitions for buffer-equal 1.0 0
2-
// Project: https://github.com/chaijs/assertion-error
2+
// Project: https://github.com/substack/node-buffer-equal
33
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
44
// Definitions: https://github.com/borisyankov/DefinitelyTyped
55

bufferstream/bufferstream-tests.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path="bufferstream.d.ts" />
2+
3+
import BufferStream = require('bufferstream')
4+
5+
var stream = new BufferStream({encoding:'utf8', size:'flexible'});
6+
stream.enable();
7+
stream.disable();
8+
stream.split('//', ':');
9+
stream.on('split', (chunk: any, token: any) => {
10+
console.log("got '%s' by '%s'", chunk.toString(), token.toString())
11+
});
12+
stream.write("buffer:stream//23");
13+
console.log(stream.toString());
14+

bufferstream/bufferstream.d.ts

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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+
}

deep-freeze/deep-freeze-tests.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="deep-freeze.d.ts" />
2+
3+
import df = require('deep-freeze');
4+
5+
class Foo {
6+
foo: string;
7+
}
8+
var foo:Foo = df(new Foo());

deep-freeze/deep-freeze.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Type definitions for deep-freeze
2+
// Project: https://github.com/substack/deep-freeze
3+
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>
4+
// Definitions: https://github.com/borisyankov/DefinitelyTyped
5+
6+
declare module 'deep-freeze' {
7+
function df<T>(obj: T): T;
8+
export = df;
9+
}

glob-stream/glob-stream-tests.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path="glob-stream" />
2+
3+
import gs = require('glob-stream');
4+
5+
var read: NodeJS.ReadableStream;
6+
7+
read = gs.create('xx');
8+
read = gs.create('xx', {});
9+
read = gs.create(['xx'], {});
10+
read = gs.create(['xx'], {cwd: 'xx'});
11+
read = gs.create(['xx'], {base: 'xx'});
12+
read = gs.create(['xx'], {cwdbase: true});

glob-stream/glob-stream.d.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Type definitions for glob-stream v3.1.12
2+
// Project: http://github.com/wearefractal/glob-stream
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+
/// <reference path="../glob/glob.d.ts" />
8+
9+
declare module 'glob-stream' {
10+
import glob = require('glob');
11+
12+
export interface Options extends glob.IOptions {
13+
cwd?: string;
14+
base?: string;
15+
cwdbase?: boolean;
16+
}
17+
18+
export interface Element {
19+
cwd: string;
20+
base: string;
21+
path: string;
22+
}
23+
24+
export function create(glob:string, opts?: Options): NodeJS.ReadableStream;
25+
export function create(globs:string[], opts?: Options): NodeJS.ReadableStream;
26+
}

0 commit comments

Comments
 (0)