-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
typings: add typing for string decoder #38229
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -51,6 +51,12 @@ const kNativeDecoder = Symbol('kNativeDecoder'); | |||||||
|
||||||||
// Do not cache `Buffer.isEncoding` when checking encoding names as some | ||||||||
// modules monkey-patch it to support additional encodings | ||||||||
/** | ||||||||
* | ||||||||
* @param {string} enc | ||||||||
* @returns {"utf8" | "utf16le" | "hex" | "ascii" | ||||||||
* | "base64" | "latin1" | "base64url"} | ||||||||
*/ | ||||||||
function normalizeEncoding(enc) { | ||||||||
const nenc = internalUtil.normalizeEncoding(enc); | ||||||||
if (nenc === undefined) { | ||||||||
|
@@ -68,12 +74,21 @@ for (let i = 0; i < encodings.length; ++i) | |||||||
// StringDecoder provides an interface for efficiently splitting a series of | ||||||||
// buffers into a series of JS strings without breaking apart multi-byte | ||||||||
// characters. | ||||||||
/** | ||||||||
* | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the above description inside the comment? |
||||||||
* @param {string} encoding | ||||||||
jasnell marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
*/ | ||||||||
function StringDecoder(encoding) { | ||||||||
this.encoding = normalizeEncoding(encoding); | ||||||||
this[kNativeDecoder] = Buffer.alloc(kSize); | ||||||||
this[kNativeDecoder][kEncodingField] = encodingsMap[this.encoding]; | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
* @param {string | Buffer | TypedArray | DataView} buf | ||||||||
* @returns {string} | ||||||||
*/ | ||||||||
StringDecoder.prototype.write = function write(buf) { | ||||||||
if (typeof buf === 'string') | ||||||||
return buf; | ||||||||
|
@@ -84,6 +99,11 @@ StringDecoder.prototype.write = function write(buf) { | |||||||
return decode(this[kNativeDecoder], buf); | ||||||||
}; | ||||||||
|
||||||||
/** | ||||||||
* | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
* @param {string | Buffer | TypedArray | DataView} buf | ||||||||
jasnell marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
* @returns {string} | ||||||||
*/ | ||||||||
StringDecoder.prototype.end = function end(buf) { | ||||||||
let ret = ''; | ||||||||
if (buf !== undefined) | ||||||||
|
@@ -94,6 +114,12 @@ StringDecoder.prototype.end = function end(buf) { | |||||||
}; | ||||||||
|
||||||||
/* Everything below this line is undocumented legacy stuff. */ | ||||||||
/** | ||||||||
* | ||||||||
* @param {string | Buffer | TypedArray | DataView} buf | ||||||||
* @param {number} offset | ||||||||
* @returns {string} | ||||||||
*/ | ||||||||
StringDecoder.prototype.text = function text(buf, offset) { | ||||||||
this[kNativeDecoder][kMissingBytes] = 0; | ||||||||
this[kNativeDecoder][kBufferedBytes] = 0; | ||||||||
|
Uh oh!
There was an error while loading. Please reload this page.