edgerender-yatl
Version:
Yet Another Template Language
41 lines • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.str2stream = void 0;
function str2ab(str) {
// should work with both browsers and node, might not be fast but shouldn't be used if performance matters
const buf = new ArrayBuffer(str.length);
const array = new Uint8Array(buf);
const str_length = str.length;
for (let i = 0; i < str_length; i++) {
array[i] = str.charCodeAt(i);
}
return array;
}
class SyntheticReader {
constructor(str) {
this.done = false;
this.str = str;
}
async read() {
if (this.done) {
return { done: true };
}
else {
this.done = true;
return { done: false, value: str2ab(this.str) };
}
}
}
class SyntheticStream {
constructor(str) {
this.str = str;
}
getReader() {
return new SyntheticReader(this.str);
}
}
function str2stream(str) {
return new SyntheticStream(str);
}
exports.str2stream = str2stream;
//# sourceMappingURL=streams.js.map