mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-18 12:33:17 +08:00
Added Buffers as return types of zlib helpers
This commit is contained in:
28
node/index.d.ts
vendored
28
node/index.d.ts
vendored
@@ -1045,20 +1045,20 @@ declare module "zlib" {
|
||||
export function createInflateRaw(options?: ZlibOptions): InflateRaw;
|
||||
export function createUnzip(options?: ZlibOptions): Unzip;
|
||||
|
||||
export function deflate(buf: Buffer, callback: (error: Error, result: any) => void): void;
|
||||
export function deflateSync(buf: Buffer, options?: ZlibOptions): any;
|
||||
export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) => void): void;
|
||||
export function deflateRawSync(buf: Buffer, options?: ZlibOptions): any;
|
||||
export function gzip(buf: Buffer, callback: (error: Error, result: any) => void): void;
|
||||
export function gzipSync(buf: Buffer, options?: ZlibOptions): any;
|
||||
export function gunzip(buf: Buffer, callback: (error: Error, result: any) => void): void;
|
||||
export function gunzipSync(buf: Buffer, options?: ZlibOptions): any;
|
||||
export function inflate(buf: Buffer, callback: (error: Error, result: any) => void): void;
|
||||
export function inflateSync(buf: Buffer, options?: ZlibOptions): any;
|
||||
export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) => void): void;
|
||||
export function inflateRawSync(buf: Buffer, options?: ZlibOptions): any;
|
||||
export function unzip(buf: Buffer, callback: (error: Error, result: any) => void): void;
|
||||
export function unzipSync(buf: Buffer, options?: ZlibOptions): any;
|
||||
export function deflate(buf: Buffer, callback: (error: Error, result: Buffer) => void): void;
|
||||
export function deflateSync(buf: Buffer, options?: ZlibOptions): Buffer;
|
||||
export function deflateRaw(buf: Buffer, callback: (error: Error, result: Buffer) => void): void;
|
||||
export function deflateRawSync(buf: Buffer, options?: ZlibOptions): Buffer;
|
||||
export function gzip(buf: Buffer, callback: (error: Error, result: Buffer) => void): void;
|
||||
export function gzipSync(buf: Buffer, options?: ZlibOptions): Buffer;
|
||||
export function gunzip(buf: Buffer, callback: (error: Error, result: Buffer) => void): void;
|
||||
export function gunzipSync(buf: Buffer, options?: ZlibOptions): Buffer;
|
||||
export function inflate(buf: Buffer, callback: (error: Error, result: Buffer) => void): void;
|
||||
export function inflateSync(buf: Buffer, options?: ZlibOptions): Buffer;
|
||||
export function inflateRaw(buf: Buffer, callback: (error: Error, result: Buffer) => void): void;
|
||||
export function inflateRawSync(buf: Buffer, options?: ZlibOptions): Buffer;
|
||||
export function unzip(buf: Buffer, callback: (error: Error, result: Buffer) => void): void;
|
||||
export function unzipSync(buf: Buffer, options?: ZlibOptions): Buffer;
|
||||
|
||||
// Constants
|
||||
export var Z_NO_FLUSH: number;
|
||||
|
||||
@@ -33,33 +33,33 @@ import {Buffer as ImportedBuffer, SlowBuffer as ImportedSlowBuffer} from "buffer
|
||||
namespace assert_tests {
|
||||
{
|
||||
assert(1 + 1 - 2 === 0, "The universe isn't how it should.");
|
||||
|
||||
|
||||
assert.deepEqual({ x: { y: 3 } }, { x: { y: 3 } }, "DEEP WENT DERP");
|
||||
|
||||
|
||||
assert.deepStrictEqual({ a: 1 }, { a: 1 }, "uses === comparator");
|
||||
|
||||
|
||||
assert.doesNotThrow(() => {
|
||||
const b = false;
|
||||
if (b) { throw "a hammer at your face"; }
|
||||
}, undefined, "What the...*crunch*");
|
||||
|
||||
|
||||
assert.equal(3, "3", "uses == comparator");
|
||||
|
||||
assert.fail(1, 2, undefined, '>');
|
||||
|
||||
|
||||
assert.ifError(0);
|
||||
|
||||
|
||||
assert.notDeepStrictEqual({ x: { y: "3" } }, { x: { y: 3 } }, "uses !== comparator");
|
||||
|
||||
|
||||
assert.notEqual(1, 2, "uses != comparator");
|
||||
|
||||
|
||||
assert.notStrictEqual(2, "2", "uses === comparator");
|
||||
|
||||
|
||||
assert.ok(true);
|
||||
assert.ok(1);
|
||||
|
||||
|
||||
assert.strictEqual(1, 1, "uses === comparator");
|
||||
|
||||
|
||||
assert.throws(() => { throw "a hammer at your face"; }, undefined, "DODGED IT");
|
||||
}
|
||||
}
|
||||
@@ -139,21 +139,21 @@ namespace fs_tests {
|
||||
fs.writeFile("thebible.txt",
|
||||
"Do unto others as you would have them do unto you.",
|
||||
assert.ifError);
|
||||
|
||||
|
||||
fs.write(1234, "test");
|
||||
|
||||
|
||||
fs.writeFile("Harry Potter",
|
||||
"\"You be wizzing, Harry,\" jived Dumbledore.",
|
||||
{
|
||||
encoding: "ascii"
|
||||
},
|
||||
assert.ifError);
|
||||
assert.ifError);
|
||||
}
|
||||
|
||||
{
|
||||
var content: string;
|
||||
var buffer: Buffer;
|
||||
|
||||
|
||||
content = fs.readFileSync('testfile', 'utf8');
|
||||
content = fs.readFileSync('testfile', { encoding: 'utf8' });
|
||||
buffer = fs.readFileSync('testfile');
|
||||
@@ -163,7 +163,7 @@ namespace fs_tests {
|
||||
fs.readFile('testfile', (err, data) => buffer = data);
|
||||
fs.readFile('testfile', { flag: 'r' }, (err, data) => buffer = data);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
var errno: string;
|
||||
fs.readFile('testfile', (err, data) => {
|
||||
@@ -172,28 +172,28 @@ namespace fs_tests {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
fs.mkdtemp('/tmp/foo-', (err, folder) => {
|
||||
console.log(folder);
|
||||
// Prints: /tmp/foo-itXde2
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
var tempDir: string;
|
||||
tempDir = fs.mkdtempSync('/tmp/foo-');
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
fs.watch('/tmp/foo-', (event, filename) => {
|
||||
console.log(event, filename);
|
||||
});
|
||||
|
||||
|
||||
fs.watch('/tmp/foo-', 'utf8', (event, filename) => {
|
||||
console.log(event, filename);
|
||||
});
|
||||
|
||||
|
||||
fs.watch('/tmp/foo-', {
|
||||
recursive: true,
|
||||
persistent: true,
|
||||
@@ -202,22 +202,22 @@ namespace fs_tests {
|
||||
console.log(event, filename);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
fs.access('/path/to/folder', (err) => { });
|
||||
|
||||
|
||||
fs.access(Buffer.from(''), (err) => { });
|
||||
|
||||
|
||||
fs.access('/path/to/folder', fs.constants.F_OK | fs.constants.R_OK, (err) => { });
|
||||
|
||||
|
||||
fs.access(Buffer.from(''), fs.constants.F_OK | fs.constants.R_OK, (err) => { });
|
||||
|
||||
|
||||
fs.accessSync('/path/to/folder');
|
||||
|
||||
|
||||
fs.accessSync(Buffer.from(''));
|
||||
|
||||
|
||||
fs.accessSync('path/to/folder', fs.constants.W_OK | fs.constants.X_OK);
|
||||
|
||||
|
||||
fs.accessSync(Buffer.from(''), fs.constants.W_OK | fs.constants.X_OK);
|
||||
}
|
||||
}
|
||||
@@ -386,14 +386,14 @@ function bufferTests() {
|
||||
namespace url_tests {
|
||||
{
|
||||
url.format(url.parse('http://www.example.com/xyz'));
|
||||
|
||||
|
||||
// https://google.com/search?q=you're%20a%20lizard%2C%20gary
|
||||
url.format({
|
||||
protocol: 'https',
|
||||
host: "google.com",
|
||||
pathname: 'search',
|
||||
query: { q: "you're a lizard, gary" }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
@@ -410,7 +410,7 @@ namespace util_tests {
|
||||
{
|
||||
// Old and new util.inspect APIs
|
||||
util.inspect(["This is nice"], false, 5);
|
||||
util.inspect(["This is nice"], { colors: true, depth: 5, customInspect: false });
|
||||
util.inspect(["This is nice"], { colors: true, depth: 5, customInspect: false });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -427,6 +427,21 @@ function stream_readable_pipe_test() {
|
||||
r.close();
|
||||
}
|
||||
|
||||
// helpers
|
||||
const compressMe = new Buffer("some data");
|
||||
|
||||
zlib.deflate(compressMe, (err: Error, result: Buffer) => zlib.inflate(result, (err: Error, result: Buffer) => result));
|
||||
const inflated = zlib.inflateSync(zlib.deflateSync(compressMe));
|
||||
|
||||
zlib.deflateRaw(compressMe, (err: Error, result: Buffer) => zlib.inflateRaw(result, (err: Error, result: Buffer) => result));
|
||||
const inflatedRaw: Buffer = zlib.inflateRawSync(zlib.deflateRawSync(compressMe));
|
||||
|
||||
zlib.gzip(compressMe, (err: Error, result: Buffer) => zlib.gunzip(result, (err: Error, result: Buffer) => result));
|
||||
const gunzipped: Buffer = zlib.gunzipSync(zlib.gzipSync(compressMe));
|
||||
|
||||
zlib.unzip(compressMe, (err: Error, result: Buffer) => result);
|
||||
const unzipped: Buffer = zlib.unzipSync(compressMe);
|
||||
|
||||
// Simplified constructors
|
||||
function simplified_stream_ctor_test() {
|
||||
new stream.Readable({
|
||||
@@ -750,7 +765,7 @@ namespace tls_tests {
|
||||
let _response: Buffer = response;
|
||||
})
|
||||
_TLSSocket = _TLSSocket.prependOnceListener("secureConnect", () => { });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
@@ -1230,7 +1245,7 @@ namespace string_decoder_tests {
|
||||
namespace child_process_tests {
|
||||
{
|
||||
childProcess.exec("echo test");
|
||||
childProcess.spawnSync("echo test");
|
||||
childProcess.spawnSync("echo test");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1393,7 +1408,7 @@ namespace process_tests {
|
||||
{
|
||||
var eventEmitter: events.EventEmitter;
|
||||
eventEmitter = process; // Test that process implements EventEmitter...
|
||||
|
||||
|
||||
var _p: NodeJS.Process = process;
|
||||
_p = p;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user