-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
153 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/// <reference types="node" /> | ||
|
||
declare class BufferList { | ||
constructor(initialData?: Buffer | Buffer[] | BufferList | BufferList[] | string); | ||
|
||
length: number; | ||
append(buffer: Buffer | Buffer[] | BufferList | BufferList[] | string): BufferList; | ||
get(index: number): number; | ||
slice(start?: number, end?: number): Buffer; | ||
shallowSlice(start?: number, end?: number): BufferList; | ||
copy(dest: Buffer, destStart?: number, srcStart?: number, srcEnd?: number): Buffer; | ||
duplicate(): BufferList; | ||
consume(bytes?: number): void; | ||
toString(encoding?: string, start?: number, end?: number): string; | ||
indexOf(value: string | number | Uint8Array | BufferList | Buffer, byteOffset?: number, encoding?: string): number; | ||
readDoubleBE(offset?: number): number; | ||
readDoubleLE(offset?: number): number; | ||
readFloatBE(offset?: number): number; | ||
readFloatLE(offset?: number): number; | ||
readInt32BE(offset?: number): number; | ||
readInt32LE(offset?: number): number; | ||
readUInt32BE(offset?: number): number; | ||
readUInt32LE(offset?: number): number; | ||
readInt16BE(offset?: number): number; | ||
readInt16LE(offset?: number): number; | ||
readUInt16BE(offset?: number): number; | ||
readUInt16LE(offset?: number): number; | ||
readInt8(offset: number): number; | ||
readUInt8(offset: number): number; | ||
readIntBE(offset: number): number; | ||
readIntLE(offset: number): number; | ||
readUIntBE(offset: number): number; | ||
readUIntLE(offset: number): number; | ||
|
||
static isBufferList(other: any): boolean; | ||
} | ||
|
||
export = BufferList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,110 @@ | ||
import BufferList = require('bl'); | ||
import BufferListStream = require("bl"); | ||
import BufferList = require("bl/BufferList"); | ||
|
||
var bl: BufferList; | ||
var bls: BufferListStream; | ||
var buffer: Buffer; | ||
var offset: number; | ||
var num: number; | ||
var str: string; | ||
|
||
bl = new BufferList(); | ||
bl = new BufferList(bl); | ||
bl = new BufferList([bl]); | ||
bl = new BufferList(Buffer.from('asdf')); | ||
bl = new BufferList([Buffer.from('asdf')]); | ||
bl = new BufferList('hi'); | ||
BufferListStream.isBufferList({}); | ||
|
||
// has Duplex methods | ||
bls.pause(); | ||
bls.resume(); | ||
|
||
var bl = new BufferList(); | ||
|
||
// is assignable | ||
bl = bls.duplicate(); | ||
|
||
// is not assignable as it lacks the Duplex methods | ||
var bls2: BufferListStream; | ||
bls2 = bl; // $ExpectError | ||
|
||
// does not have Duplex methods | ||
bl.pause(); // $ExpectError | ||
bl.resume(); // $ExpectError | ||
|
||
bl.append(buffer); | ||
num = bl.length; | ||
|
||
num = bl.get(num); | ||
|
||
buffer = bl.slice(num, num); | ||
buffer = bl.slice(num); | ||
buffer = bl.slice(); | ||
bl.shallowSlice(0, 1).shallowSlice(); | ||
|
||
bl.copy(buffer, num, num, num); | ||
bl.copy(buffer, num, num); | ||
bl.copy(buffer, num); | ||
bl.copy(buffer); | ||
|
||
bl = bl.duplicate(); | ||
|
||
bl.consume(); | ||
bl.consume(num); | ||
|
||
str = bl.toString(str, num, num); | ||
str = bl.toString(str, num); | ||
str = bl.toString(str); | ||
str = bl.toString(); | ||
bl.indexOf('foo', 0, 'hex') === 1; | ||
bl.indexOf(Buffer.from('foo')) === 1; | ||
bl.indexOf(4) === 1; | ||
bl.indexOf(bl) === 1; | ||
bl.indexOf(new Uint8Array([1, 3, 4])) === 2; | ||
|
||
num = bl.readDoubleBE(offset); | ||
num = bl.readDoubleBE(offset); | ||
num = bl.readDoubleLE(offset); | ||
num = bl.readDoubleLE(offset); | ||
num = bl.readFloatBE(offset); | ||
num = bl.readFloatBE(offset); | ||
num = bl.readFloatLE(offset); | ||
num = bl.readFloatLE(offset); | ||
num = bl.readInt32BE(offset); | ||
num = bl.readInt32BE(offset); | ||
num = bl.readInt32LE(offset); | ||
num = bl.readInt32LE(offset); | ||
num = bl.readUInt32BE(offset); | ||
num = bl.readUInt32BE(offset); | ||
num = bl.readUInt32LE(offset); | ||
num = bl.readUInt32LE(offset); | ||
num = bl.readInt16BE(offset); | ||
num = bl.readInt16BE(offset); | ||
num = bl.readInt16LE(offset); | ||
num = bl.readInt16LE(offset); | ||
num = bl.readUInt16BE(offset); | ||
num = bl.readUInt16BE(offset); | ||
num = bl.readUInt16LE(offset); | ||
num = bl.readUInt16LE(offset); | ||
num = bl.readInt8(offset); | ||
num = bl.readInt8(offset); | ||
num = bl.readUInt8(offset); | ||
num = bl.readUInt8(offset); | ||
bl.append(bl); | ||
bl.append(bls); | ||
|
||
bls = new BufferListStream(); | ||
bls = new BufferListStream(bls); | ||
bls = new BufferListStream([bls]); | ||
bls = new BufferListStream(Buffer.from("asdf")); | ||
bls = new BufferListStream([Buffer.from("asdf")]); | ||
bls = new BufferListStream("hi"); | ||
|
||
bls.append(buffer); | ||
bls.append(bl); | ||
bls.append(bls); | ||
num = bls.length; | ||
|
||
num = bls.get(num); | ||
|
||
buffer = bls.slice(num, num); | ||
buffer = bls.slice(num); | ||
buffer = bls.slice(); | ||
bls.shallowSlice(0, 1).shallowSlice(); | ||
|
||
bls.copy(buffer, num, num, num); | ||
bls.copy(buffer, num, num); | ||
bls.copy(buffer, num); | ||
bls.copy(buffer); | ||
|
||
bls = bls.duplicate(); | ||
|
||
bls.consume(); | ||
bls.consume(num); | ||
|
||
str = bls.toString(str, num, num); | ||
str = bls.toString(str, num); | ||
str = bls.toString(str); | ||
str = bls.toString(); | ||
bls.indexOf("foo", 0, "hex") === 1; | ||
bls.indexOf(Buffer.from("foo")) === 1; | ||
bls.indexOf(4) === 1; | ||
bls.indexOf(bls) === 1; | ||
bls.indexOf(new Uint8Array([1, 3, 4])) === 2; | ||
bls.indexOf(bl) === 0; | ||
bl.indexOf(bls) === 0; | ||
|
||
num = bls.readDoubleBE(offset); | ||
num = bls.readDoubleBE(offset); | ||
num = bls.readDoubleLE(offset); | ||
num = bls.readDoubleLE(offset); | ||
num = bls.readFloatBE(offset); | ||
num = bls.readFloatBE(offset); | ||
num = bls.readFloatLE(offset); | ||
num = bls.readFloatLE(offset); | ||
num = bls.readInt32BE(offset); | ||
num = bls.readInt32BE(offset); | ||
num = bls.readInt32LE(offset); | ||
num = bls.readInt32LE(offset); | ||
num = bls.readUInt32BE(offset); | ||
num = bls.readUInt32BE(offset); | ||
num = bls.readUInt32LE(offset); | ||
num = bls.readUInt32LE(offset); | ||
num = bls.readInt16BE(offset); | ||
num = bls.readInt16BE(offset); | ||
num = bls.readInt16LE(offset); | ||
num = bls.readInt16LE(offset); | ||
num = bls.readUInt16BE(offset); | ||
num = bls.readUInt16BE(offset); | ||
num = bls.readUInt16LE(offset); | ||
num = bls.readUInt16LE(offset); | ||
num = bls.readInt8(offset); | ||
num = bls.readInt8(offset); | ||
num = bls.readUInt8(offset); | ||
num = bls.readUInt8(offset); | ||
num = bls.readIntBE(offset); | ||
num = bls.readIntLE(offset); | ||
num = bls.readUIntBE(offset); | ||
num = bls.readUIntLE(offset); | ||
|
||
BufferListStream.isBufferList(bls); // $ExpectTrue | ||
BufferListStream.isBufferList({}); // $ExpectFalse | ||
BufferList.isBufferList(bl); // $ExpectTrue | ||
BufferList.isBufferList({}); // $ExpectFalse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,23 @@ | ||
// Type definitions for BufferList v4.1 | ||
// Type definitions for BufferList v5.0 | ||
// Project: https://github.com/rvagg/bl | ||
// Definitions by: Bart van der Schoor <https://github.com/Bartvds> | ||
// Francis Gulotta <https://github.com/reconbot> | ||
// Ben Allfree <https://github.com/benallfree> | ||
// Alex Potsides <https://github.com/achingbrain> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
||
/// <reference types="node" /> | ||
|
||
declare class BufferList { | ||
constructor(initialData?: Buffer | Buffer[] | BufferList | BufferList[] | string); | ||
import BufferList = require("./BufferList"); | ||
import { Duplex } from "readable-stream"; | ||
|
||
interface BufferListStream extends Duplex, BufferList {} | ||
|
||
length: number; | ||
append(buffer: Buffer | Buffer[] | BufferList | BufferList[] | string): BufferList; | ||
get(index: number): number; | ||
slice(start?: number, end?: number): Buffer; | ||
shallowSlice(start?: number, end?: number): BufferList; | ||
copy(dest: Buffer, destStart?: number, srcStart?: number, srcEnd?: number): Buffer; | ||
duplicate(): BufferList; | ||
consume(bytes?: number): void; | ||
toString(encoding?: string, start?: number, end?: number): string; | ||
indexOf(value: string | number | Uint8Array | BufferList | Buffer, byteOffset?: number, encoding?: string): number; | ||
readDoubleBE(offset?: number): number; | ||
readDoubleLE(offset?: number): number; | ||
readFloatBE(offset?: number): number; | ||
readFloatLE(offset?: number): number; | ||
readInt32BE(offset?: number): number; | ||
readInt32LE(offset?: number): number; | ||
readUInt32BE(offset?: number): number; | ||
readUInt32LE(offset?: number): number; | ||
readInt16BE(offset?: number): number; | ||
readInt16LE(offset?: number): number; | ||
readUInt16BE(offset?: number): number; | ||
readUInt16LE(offset?: number): number; | ||
readInt8(offset: number): number; | ||
readUInt8(offset: number): number; | ||
declare class BufferListStream { | ||
constructor(initialData?: Buffer | Buffer[] | BufferList | BufferList[] | string); | ||
static isBufferList: (other: any) => boolean; | ||
duplicate: () => BufferListStream; | ||
shallowSlice(start?: number, end?: number): BufferListStream; | ||
} | ||
export = BufferList; | ||
|
||
export = BufferListStream; |