Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_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
}
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);
}
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)
}
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;
constructor(from)
{
super();
this.iconv = new iconv.decodeStream(from);
this.iconv.on('data', chunk => {
this.push(chunk);
});
}
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();
}
function convertFrom (encoding) {
return splicer([
iconv.decodeStream(encoding),
iconv.encodeStream('utf8')
])
}
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;
}
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);
constructor({ fromCharSet = 'utf8' }) {
check(fromCharSet, String);
this.stream = iconv.decodeStream(fromCharSet);
}