@pkerschbaum/code-oss-file-service
Version:
VS Code ([microsoft/vscode](https://github.com/microsoft/vscode)) includes a rich "`FileService`" and "`DiskFileSystemProvider`" abstraction built on top of Node.js core modules (`fs`, `path`) and Electron's `shell` module. This package allows to use that
59 lines • 2.23 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.LineDecoder = void 0;
const sd = require("string_decoder");
/**
* Convenient way to iterate over output line by line. This helper accommodates for the fact that
* a buffer might not end with new lines all the way.
*
* To use:
* - call the write method
* - forEach() over the result to get the lines
*/
class LineDecoder {
constructor(encoding = 'utf8') {
this.stringDecoder = new sd.StringDecoder(encoding);
this.remaining = null;
}
write(buffer) {
const result = [];
const value = this.remaining
? this.remaining + this.stringDecoder.write(buffer)
: this.stringDecoder.write(buffer);
if (value.length < 1) {
return result;
}
let start = 0;
let ch;
let idx = start;
while (idx < value.length) {
ch = value.charCodeAt(idx);
if (ch === 13 /* CarriageReturn */ || ch === 10 /* LineFeed */) {
result.push(value.substring(start, idx));
idx++;
if (idx < value.length) {
const lastChar = ch;
ch = value.charCodeAt(idx);
if ((lastChar === 13 /* CarriageReturn */ && ch === 10 /* LineFeed */) || (lastChar === 10 /* LineFeed */ && ch === 13 /* CarriageReturn */)) {
idx++;
}
}
start = idx;
}
else {
idx++;
}
}
this.remaining = start < value.length ? value.substr(start) : null;
return result;
}
end() {
return this.remaining;
}
}
exports.LineDecoder = LineDecoder;
//# sourceMappingURL=decoder.js.map
;