Skip to content

Commit bff485b

Browse files
committed
Replace iconv with iconv-lite
1 parent 82fea4d commit bff485b

4 files changed

Lines changed: 31 additions & 35 deletions

File tree

examples/compressed.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var request = require('request')
22
, FeedParser = require(__dirname+'/..')
3-
, Iconv = require('iconv').Iconv
3+
, iconv = require('iconv-lite')
44
, zlib = require('zlib');
55

66
function fetch(feed) {
@@ -46,16 +46,16 @@ function maybeDecompress (res, encoding) {
4646
}
4747

4848
function maybeTranslate (res, charset) {
49-
var iconv;
50-
// Use iconv if its not utf8 already.
51-
if (!iconv && charset && !/utf-*8/i.test(charset)) {
49+
var iconvStream;
50+
// Decode using iconv-lite if its not utf8 already.
51+
if (!iconvStream && charset && !/utf-*8/i.test(charset)) {
5252
try {
53-
iconv = new Iconv(charset, 'utf-8');
53+
iconvStream = iconv.decodeStream(charset);
5454
console.log('Converting from charset %s to utf-8', charset);
55-
iconv.on('error', done);
56-
// If we're using iconv, stream will be the output of iconv
55+
iconvStream.on('error', done);
56+
// If we're using iconvStream, stream will be the output of iconvStream
5757
// otherwise it will remain the output of request
58-
res = res.pipe(iconv);
58+
res = res.pipe(iconvStream);
5959
} catch(err) {
6060
res.emit('error', err);
6161
}

examples/iconv.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
var request = require('request')
99
, FeedParser = require(__dirname+'/..')
10-
, Iconv = require('iconv').Iconv;
10+
, iconv = require('iconv-lite');
1111

1212
function fetch(feed) {
1313
// Define our streams
@@ -40,16 +40,16 @@ function fetch(feed) {
4040
}
4141

4242
function maybeTranslate (res, charset) {
43-
var iconv;
44-
// Use iconv if its not utf8 already.
45-
if (!iconv && charset && !/utf-*8/i.test(charset)) {
43+
var iconvStream;
44+
// Decode using iconv-lite if its not utf8 already.
45+
if (!iconvStream && charset && !/utf-*8/i.test(charset)) {
4646
try {
47-
iconv = new Iconv(charset, 'utf-8');
47+
iconvStream = iconv.decodeStream(charset);
4848
console.log('Converting from charset %s to utf-8', charset);
49-
iconv.on('error', done);
50-
// If we're using iconv, stream will be the output of iconv
49+
iconvStream.on('error', done);
50+
// If we're using iconvStream, stream will be the output of iconvStream
5151
// otherwise it will remain the output of request
52-
res = res.pipe(iconv);
52+
res = res.pipe(iconvStream);
5353
} catch(err) {
5454
res.emit('error', err);
5555
}

package-lock.json

Lines changed: 14 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
},
4848
"devDependencies": {
4949
"eslint": "^4.8.0",
50-
"iconv": "^2.3.0",
50+
"iconv-lite": "^0.5.1",
5151
"mocha": "^5.0.0",
5252
"request": "^2.83.0"
5353
},

0 commit comments

Comments
 (0)