Skip to content

Commit

Permalink
Merge pull request #159 from dduponchel/issue_151
Browse files Browse the repository at this point in the history
Remove usage of Text{En,De}coder.
  • Loading branch information
Stuk committed Jul 22, 2014
2 parents 153f3f3 + 8e25faa commit af1a437
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 31 deletions.
8 changes: 0 additions & 8 deletions lib/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ var utf8 = require('./utf8');
var StringWriter = require('./stringWriter');
var Uint8ArrayWriter = require('./uint8ArrayWriter');

var textEncoder;
if (support.uint8array && typeof TextEncoder === "function") {
textEncoder = new TextEncoder("utf-8");
}

/**
* Returns the raw data of a ZipObject, decompress the content if necessary.
* @param {ZipObject} file the file to use.
Expand Down Expand Up @@ -54,9 +49,6 @@ var getBinaryData = function(file) {
if (!file.options.binary) {
// unicode text !
// unicode string => binary string is a painful process, check if we can avoid it.
if (textEncoder) {
return textEncoder.encode(result);
}
if (support.nodebuffer) {
return nodeBuffer(result, "utf-8");
}
Expand Down
23 changes: 0 additions & 23 deletions lib/utf8.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@ var utils = require('./utils');
var support = require('./support');
var nodeBuffer = require('./nodeBuffer');

var textEncoder, textDecoder;
if (
support.uint8array &&
typeof TextEncoder === "function" &&
typeof TextDecoder === "function"
) {
textEncoder = new TextEncoder("utf-8");
textDecoder = new TextDecoder("utf-8");
}

/**
* The following functions come from pako, from pako/lib/utils/strings
* released under the MIT license, see pako https://github.com/nodeca/pako/
Expand Down Expand Up @@ -176,12 +166,6 @@ var buf2string = function (buf) {
* @return {Array|Uint8Array|Buffer} the UTF-8 encoded string.
*/
exports.utf8encode = function utf8encode(str) {
// TextEncoder + Uint8Array to binary string is faster than checking every bytes on long strings.
// http://jsperf.com/utf8encode-vs-textencoder
// On short strings (file names for example), the TextEncoder API is (currently) slower.
if (textEncoder) {
return textEncoder.encode(str);
}
if (support.nodebuffer) {
return nodeBuffer(str, "utf-8");
}
Expand All @@ -197,13 +181,6 @@ exports.utf8encode = function utf8encode(str) {
* @return {String} the decoded string.
*/
exports.utf8decode = function utf8decode(buf) {
// check if we can use the TextDecoder API
// see http://encoding.spec.whatwg.org/#api
if (textDecoder) {
return textDecoder.decode(
utils.transformTo("uint8array", buf)
);
}
if (support.nodebuffer) {
return utils.transformTo("nodebuffer", buf).toString("utf-8");
}
Expand Down

0 comments on commit af1a437

Please sign in to comment.