univ-conv
Version:
The universal binary and text converter
27 lines • 952 B
JavaScript
import { _ } from "./AbstractConverter";
import { isBuffer } from "./Environment";
import { TextHelper } from "./TextHelper";
export class NodeTextHelper extends TextHelper {
async bufferToText(buf, options) {
let buffer;
if (isBuffer(buf)) {
buffer = buf;
}
else {
buffer = (await _().convert("uint8array", buf));
}
const bufCharset = options.bufferToTextCharset;
if (bufCharset === "utf8" || bufCharset === "utf16le") {
return buffer.toString(bufCharset);
}
return await super.bufferToText(buf, options);
}
async textToBuffer(text, options) {
const bufCharset = options.textToBufferCharset;
if (bufCharset === "utf8" || bufCharset === "utf16le") {
return Buffer.from(text, bufCharset);
}
return await super.textToBuffer(text, options);
}
}
//# sourceMappingURL=NodeTextHelper.js.map