UNPKG

genshin-manager

Version:

<div align="center"> <p> <a href="https://www.npmjs.com/package/genshin-manager"><img src="https://img.shields.io/npm/v/genshin-manager.svg?maxAge=3600" alt="npm version" /></a> <a href="https://www.npmjs.com/package/genshin-manager"><img src="https:

53 lines (52 loc) 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TextMapEmptyWritable = void 0; const stream_1 = require("stream"); /** * TextMapEmptyWritable */ class TextMapEmptyWritable extends stream_1.Writable { constructor() { super(...arguments); this.buffer = Buffer.from(''); } /** * Create a TextMapEmptyWritable * @param chunk Buffer * @param encoding Encoding * @param callback Callback */ _write(chunk, encoding, callback) { const combinedBuffer = Buffer.concat([this.buffer, chunk]); const lineBuffers = this.splitBuffer(combinedBuffer, Buffer.from('\n')); this.buffer = lineBuffers.pop() || Buffer.from(''); if (lineBuffers.length === 0) { callback(); return; } const lines = lineBuffers.map((buffer) => buffer.toString()); lines.forEach((line) => { const matchArray = line.match(/(?<=")([^"\\]|\\.)*?(?=")/g); if (!matchArray) return; const [key, , value] = matchArray; this.emit('data', { key: key, value: value.replace(/\\n/g, '\n'), }); }); callback(); } splitBuffer(array, separator) { const result = []; let start = 0; let index; while ((index = array.indexOf(separator, start)) !== -1) { result.push(array.slice(start, index)); start = index + separator.length; } result.push(array.slice(start)); return result; } } exports.TextMapEmptyWritable = TextMapEmptyWritable;