How to use the iconv-lite.encodeStream function in iconv-lite

To help you get started, we’ve selected a few iconv-lite examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GetStream / Winds / api / services / parse.js View on Github external
function maybeTranslate(res, charset) {
    const iconv = require('iconv-lite')

    // use iconv if its not utf8 already.
    if (charset && !/utf-*8/i.test(charset)) {
        try {
            res.pipe(
                iconv.decodeStream(charset)
            ).pipe(
                iconv.encodeStream('utf-8')
            )
        } catch (err) {
            res.emit('error', err);
        }
    }

    return res;

}
github ezpaarse-project / ezpaarse / lib / init / init-writer.js View on Github external
function getWriterOutputStream(resType, ext) {
    var stream;

    if (zipExt) { ext += zipExt; }

    job.contentType   = resType;
    job.fileExtension = ext;

    var zipStream = getZipStream();

    if (!job.resIsDeferred) {
      stream = iconv.encodeStream(job.outputCharset || 'utf-8');
      if (zipStream) { stream = stream.pipe(zipStream); }
      stream.pipe(res);
      return stream;
    }

    job.logger.info('Deferred response requested: ECs will be writen in a temp file');

    var date = moment().format('YYYY-MM-DD_HH[h]mm');

    // create a file writer stream to store ECs into
    job.ecsPath       = path.join(job.jobPath, date + '.job-ecs.' + ext);
    job.ecsStreamEnd  = false;

    var jobPath = job.jobPath;
    var reg     = /.*\.job-ecs(\.[a-z]+){1,2}$/;
    var files   = fs.readdirSync(jobPath);
github heldinz / gulp-convert-encoding / index.js View on Github external
return through.obj(function (file, enc, cb) {

		if (file.isNull()) {
			this.push(file);
			cb();
			return;
		}

		if (file.isStream()) {
			try {
				file.contents = file.contents
					.pipe(iconv.decodeStream(options.from, options.iconv.decode))
					.pipe(iconv.encodeStream(options.to, options.iconv.encode));
				this.push(file);
			} catch (err) {
				this.emit('error', new pluginError('gulp-convert-encoding', err));
			}
		}

		if (file.isBuffer()) {
			try {
				var content = iconv.decode(file.contents, options.from, options.iconv.decode);
				file.contents = iconv.encode(content, options.to, options.iconv.encode);
				this.push(file);
			} catch (err) {
				this.emit('error', new pluginError('gulp-convert-encoding', err));
			}
		}
github avwo / whistle / lib / util / index.js View on Github external
pipeStream.addTail(function(src, next) {
      next(src.pipe(iconv.encodeStream(charset)));
    });
  }
github avwo / whistle / lib / inspectors / https / transform.js View on Github external
var unzip, zip, stream, result;
	switch (headers['content-encoding']) {
	    case 'gzip':
	    	unzip = zlib.createGunzip();
	    	zip = zlib.createGzip();
	      break;
	    case 'deflate':
	    	unzip = zlib.createInflate();
	    	zip = zlib.createDeflate();
	      break;
	}
	
	
	if (unzip) {
		res = res.pipe(unzip).pipe(iconv.decodeStream(charset));
		stream = iconv.encodeStream(charset);
		result = stream.pipe(zip);
	} else {
		res = res.pipe(iconv.decodeStream(charset));
		result = stream = iconv.encodeStream(charset);
	}
	
	var rest = '';
	res.on('data', function(data) {
		var len = data.length - 7;
		if (len > 0) {
			data = (rest + data).replace(WHISTLE_SSL_RE, 'http://' + HTTPS_FLAG);
			rest = data.substring(len);
			data = data.substring(0, len);
			stream.write(data, charset);
		} else {
			rest = data;
github jeresig / pharos-images / converters / frick.js View on Github external
processFiles(fileStreams, callback) {
        const results = [];

        fileStreams[0]
            .pipe(iconv.decodeStream("macintosh"))
            .pipe(iconv.encodeStream("utf8"))
            .pipe(csv({
                objectMode: true,
                delimiter: "\t",
                newline: "\n",
                columns: true,
            }))
            .on("data", (data) => {
                if (data.bibRecordNumberLong) {
                    const result = searchByProps(data, propMap);
                    if (result.id) {
                        result.lang = "en";
                        results.push(result);
                    }
                }
            })
            .on("error", callback)
github finnp / to-utf-8 / index.js View on Github external
function convertFrom (encoding) {
  return splicer([
    iconv.decodeStream(encoding),
    iconv.encodeStream('utf8')
  ])
}
github jacktuck / unfurl / index.js View on Github external
const pkg = {
      other: {
        contentType,
        contentLength
      }
    }

    const multibyteEncodings = [ 'CP932', 'CP936', 'CP949', 'CP950', 'GB2312', 'GBK', 'GB18030', 'Big5', 'Shift_JIS', 'EUC-JP' ]

    if (multibyteEncodings.includes(charset)) {
      log('converting multibyte encoding from', charset, 'to utf-8')

      res.body = res.body
        .pipe(iconv.decodeStream(charset))
        .pipe(iconv.encodeStream('utf-8'))
    }

    return [pkg, res]
  })
}
github microsoft / vscode / src / vs / base / node / encoding.ts View on Github external
export function encodeStream(encoding: string, options?: { addBOM?: boolean }): NodeJS.ReadWriteStream {
	return iconv.encodeStream(toNodeEncoding(encoding), options);
}