-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[@types/bl] update bl types to v5 #52236
Merged
typescript-bot
merged 12 commits into
DefinitelyTyped:master
from
achingbrain:update-bl-types
Apr 9, 2021
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
77c02f5
[@types/bl] update bl types to v5
achingbrain 5431b26
add package.json for bl
achingbrain da784f0
update dep path
achingbrain 034ecf0
update dep path
achingbrain d5e5eb9
remove package.json
achingbrain 5708bab
remove named exports
achingbrain ed63713
add missing methods and tests for those methods
achingbrain a014520
revert import type change and remove extra header
achingbrain 92a8f4b
add BufferList to indexOf
achingbrain c1a8757
rename variables in tests so it is clearer what is going on
achingbrain 3383b02
use interface for multiple inheritance
achingbrain da6f9c1
apply prettier
achingbrain File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the v4 types still in widespread use and, if so, will they need to be updated (e.g. to fix bugs)? If so, it might be desirable to split out a separate directory for them (see the readme).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the readme:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amcasey I'm one of the maintainers of this package; not sure if your suggestion is worthwhile only because @rvagg has expressed interest #52236 (comment) in moving this into
bl
as a first-class citizen and existing users can pin the @types/bl package version they need in the mean time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benallfree Creating an old-version directory is very optional and I was simply asking whether it would be beneficial for this package. Having said that, I'm not sure I understand how the comment you linked answers the question - first class types would be great but users of v4 would still consume
@types/bl
and might still want bug fixes for those types. If usage of v4 is limited or if the types are simple enough to be "obviously correct", then it's probably not worthwhile.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amcasey Sorry yes I meant to say that I see your point and it could be valuable to maintain older versions. There are already known issues/shortcomings with the v4 typings, for example.
I was attempting to balance that against how much longer this package would need to be maintained, but now that I think about it more, I realize that this @types/bl package can really never be deprecated because older versions of bl still need it.
So I agree with you now :) We should folder-ize this package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is necessary, at least not yet - the bump from v4 to v5 happened because the underlying buffer browser polyfill jumped from v5 to v6, removing ie11 and Safari < 10 support, not because there was any API breakage.
Would it be better to hold off creating folders until there's a release that breaks the API, give that if we create folders now the contents of v4 and v5 would be identical?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@achingbrain Hmm I agree with your point too! I'm good either way 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@achingbrain I'm not sure I understand your suggestion. I think you're saying that users currently consuming bl@4 should start consuming @types/bl@5 because the APIs are compatible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To reiterate though, I'm fine with not creating a v4 directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amcasey yes, that’s what I’m saying - the APIs are compatible.