How to use the iconv-lite.decodeStream 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 node-link / minecord / src / Tail.js View on Github external
_handleChangeFile (stats) {
    if (stats.size < this.position) this.position = 0

    if (!stats.size) return

    createInterface({
      input: createReadStream(this.filename, {
        start: this.position,
        end: stats.size - 1,
      }).pipe(decodeStream(this.encode))
    }).on('line', line => {
      this.emit('line', line)
    })

    this.position = stats.size
  }
github avwo / whistle / lib / util / index.js View on Github external
function getPipeIconvStream(headers, plainText) {
  var pipeStream = new PipeStream();
  var charset = getCharset(headers['content-type']);

  if (charset) {
    pipeStream.addHead(iconv.decodeStream(charset));
    pipeStream.addTail(iconv.encodeStream(charset));
  } else {
    pipeStream.addHead(function(res, next) {
      var buffer, iconvDecoder;
      var decoder = new StringDecoder();
      var content = '';

      res.on('data', function(chunk) {
        buffer = buffer ? Buffer.concat([buffer, chunk]) : chunk;
        if (!charset) {
          try {
            content += chunk ? decoder.write(chunk) : decoder.end();
          } catch(e) {//可能抛出异常RangeError: out of range index,具体原因未知
            content = (buffer || '') + '';
            logger.error(e);
          }
github etalab / decoupage-administratif / build / util.js View on Github external
async function extractDataFromFile(path) {
  const [file] = await decompress(path)
  const stream = pumpify(
    intoStream(file.data),
    decodeStream('win1252'),
    parse({separator: '\t', strict: true})
  )
  return getStream(stream)
}
github streetsidesoftware / cspell / packages / cspell-tools / dist / fileReader.js View on Github external
function textFileStreamRx(filename, encoding = 'UTF-8') {
    const subject = new Rx.Subject();
    const fnError = (e) => subject.error(e);
    const pipes = [];
    if (filename.match(/\.gz$/i)) {
        pipes.push(zlib.createGunzip());
    }
    pipes.push(iconv.decodeStream(encoding));
    const fileStream = fs.createReadStream(filename);
    fileStream.on('error', fnError);
    const stream = pipes.reduce((s, p) => s.pipe(p).on('error', fnError), fileStream);
    stream.on('end', () => subject.complete());
    const streamData = Rx.Observable.fromEvent(stream, 'data');
    streamData.subscribe(s => subject.next(s));
    return subject;
}
exports.textFileStreamRx = textFileStreamRx;
github avz / jl-sql / src / stream / Iconv.js View on Github external
constructor(from)
	{
		super();

		this.iconv = new iconv.decodeStream(from);

		this.iconv.on('data', chunk => {
			this.push(chunk);
		});
	}
github avwo / whistle / lib / util / index.js View on Github external
function resolveCharset(chunk) {
        if (!charset && (!chunk || content.length >= 51200)) {
          charset = content.indexOf('�') != -1 ? 'gbk' : 'utf8';
          content = null;
        }

        if (!charset) {
          return;
        }

        if (!iconvDecoder) {
          iconvDecoder = iconv.decodeStream(charset);
          next(iconvDecoder);
        }

        if (buffer) {
          iconvDecoder.write(buffer);
          buffer = null;
        }

        !chunk && iconvDecoder.end();
      }
github finnp / to-utf-8 / index.js View on Github external
function convertFrom (encoding) {
  return splicer([
    iconv.decodeStream(encoding),
    iconv.encodeStream('utf8')
  ])
}
github streetsidesoftware / cspell / packages / cspell-lib / src / file / fileReader.ts View on Github external
function prepareFileStream(
    filename: string,
    encoding: string,
    fnError: (e: Error) => void,
) {
    const pipes: NodeJS.ReadWriteStream[] = [];
    if (filename.match(/\.gz$/i)) {
        pipes.push(zlib.createGunzip());
    }
    pipes.push(iconv.decodeStream(encoding));
    const fileStream = fs.createReadStream(filename);
    fileStream.on('error', fnError);
    const stream = pipes.reduce((s, p) => s.pipe(p!).on('error', fnError), fileStream);
    return stream;
}
github avwo / whistle / lib / inspectors / https / transform.js View on Github external
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;
		}
	}).on('end', function() {
		stream.end(rest, charset);
github sozialhelden / accessibility-cloud / both / api / sources / server / stream-chain / stream-types / convert-to-utf8.js View on Github external
constructor({ fromCharSet = 'utf8' }) {
    check(fromCharSet, String);
    this.stream = iconv.decodeStream(fromCharSet);
  }