Socket
Socket
Sign inDemoInstall

iconv-lite

Package Overview
Dependencies
0
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.2.1

.travis.yml

68

index.js

@@ -68,8 +68,3 @@ // Module exports

if (!options.charsBuf) {
options.charsBuf = new Buffer(256*2);
for (var i = 0; i < options.chars.length; i++) {
var code = options.chars.charCodeAt(i);
options.charsBuf[i*2+0] = code & 0xFF;
options.charsBuf[i*2+1] = code >>> 8;
}
options.charsBuf = new Buffer(options.chars, 'ucs2');
}

@@ -100,3 +95,3 @@

// As string are immutable in JS, we use ucs2 buffer to speed up computations.
// Strings are immutable in JS -> we use ucs2 buffer to speed up computations.
var charsBuf = options.charsBuf;

@@ -131,17 +126,17 @@ var newBuf = new Buffer(buf.length*2);

str = ensureString(str);
var len = 0, strLen = str.length;
for (var i = 0; i < strLen; i++) {
if (!!(str.charCodeAt(i) >> 8)) {
len += 2;
} else {
len ++;
}
}
var newBuf = new Buffer(len);
var strLen = str.length;
var bufLen = strLen;
for (var i = 0; i < strLen; i++)
if (str.charCodeAt(i) >> 7)
bufLen++;
var newBuf = new Buffer(bufLen), gbkcode, unicode,
defaultChar = revCharsTable[iconv.defaultCharUnicode.charCodeAt(0)];
for (var i = 0, j = 0; i < strLen; i++) {
var unicode = str.charCodeAt(i);
if (!!(unicode >> 7)) {
var gbkcode = revCharsTable[unicode] || revCharsTable[iconv.defaultCharUnicode.charCodeAt(0)];//not found in table ,replace it
newBuf[j++] = gbkcode >> 8;//high byte;
newBuf[j++] = gbkcode & 0xFF;//low byte
unicode = str.charCodeAt(i);
if (unicode >> 7) {
gbkcode = revCharsTable[unicode] || defaultChar;
newBuf[j++] = gbkcode >> 8; //high byte;
newBuf[j++] = gbkcode & 0xFF; //low byte
} else {//ascii

@@ -155,20 +150,21 @@ newBuf[j++] = unicode;

buf = ensureBuffer(buf);
var idx = 0, len = 0,
newBuf = new Buffer(len*2),unicode,gbkcode;
for (var i = 0, _len = buf.length; i < _len; i++, len++) {
if (!!(buf[i] & 0x80)) {//the high bit is 1, so this byte is gbkcode's high byte.skip next byte
var bufLen = buf.length, strLen = 0;
for (var i = 0; i < bufLen; i++) {
strLen++;
if (buf[i] & 0x80) //the high bit is 1, so this byte is gbkcode's high byte.skip next byte
i++;
}
}
var newBuf = new Buffer(len*2);
for (var i = 0, j = 0, _len = buf.length; i < _len; i++, j++) {
var temp = buf[i], gbkcode, unicode;
if (temp & 0x80) {
gbkcode = (temp << 8) + buf[++i];
unicode = table[gbkcode] || iconv.defaultCharUnicode.charCodeAt(0);//not found in table, replace with defaultCharUnicode
}else {
unicode = temp;
var newBuf = new Buffer(strLen*2), unicode, gbkcode,
defaultChar = iconv.defaultCharUnicode.charCodeAt(0);
for (var i = 0, j = 0; i < bufLen; i++, j+=2) {
gbkcode = buf[i];
if (gbkcode & 0x80) {
gbkcode = (gbkcode << 8) + buf[++i];
unicode = table[gbkcode] || defaultChar;
} else {
unicode = gbkcode;
}
newBuf[j*2] = unicode & 0xFF;//low byte
newBuf[j*2+1] = unicode >> 8;//high byte
newBuf[j] = unicode & 0xFF; //low byte
newBuf[j+1] = unicode >> 8; //high byte
}

@@ -175,0 +171,0 @@ return newBuf.toString('ucs2');

{
"name": "iconv-lite",
"description": "Convert character encodings in pure javascript.",
"version": "0.2.0",
"version": "0.2.1",

@@ -23,2 +23,5 @@ "keywords": ["iconv", "convert", "charset"],

},
"scripts": {
"test": "vows --spec"
},
"devDependencies": {

@@ -25,0 +28,0 @@ "vows": "",

iconv-lite - pure javascript character encoding conversion
======================================================================
[![Build Status](https://secure.travis-ci.org/ashtuchkin/iconv-lite.png?branch=master)](http://travis-ci.org/ashtuchkin/iconv-lite)
## Features
* Pure javascript. Doesn't need native code compilation.
* Easy API.
* Works on Windows and in sandboxed environments like [Cloud9](http://c9.io) (doesn't need native code compilation).
* Faster than iconv (see below for performance comparison).
* Works on Windows and in sandboxed environments like [Cloud9](http://c9.io).
* Encoding is faster than node-iconv, decoding slightly slower (see below for performance comparison).

@@ -36,8 +39,8 @@ ## Usage

Comparison with iconv module (1000 times 256kb, on Core i5/2.5 GHz).
Comparison with node-iconv module (1000 times 256kb, on Core i5/2.5 GHz, Node v0.6.17).
operation iconv iconv-lite (this module)
----------------------------------------------------------
encode('win1251') 19.57 mb/s 49.04 mb/s
decode('win1251') 16.39 mb/s 24.11 mb/s
encode('win1251') ~30 Mb/s ~45 Mb/s
decode('win1251') ~33 Mb/s ~27 Mb/s

@@ -53,2 +56,5 @@

vows
# To view performance:
node test/performance.js

@@ -55,0 +61,0 @@ ## TODO

@@ -30,2 +30,10 @@ var vows = require('vows'),

},
"GBK correctly decodes and encodes characters · and ×": function() {
// https://github.com/ashtuchkin/iconv-lite/issues/13
// Reference: http://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP936.TXT
var chars = "·×";
var gbkChars = new Buffer([0xA1, 0xA4, 0xA1, 0xC1]);
assert.strictEqual(iconv.toEncoding(chars, "GBK").toString('binary'), gbkChars.toString('binary'));
assert.strictEqual(iconv.fromEncoding(gbkChars, "GBK"), chars)
},
}).export(module)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc