Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const styledStream = createStyleStream(projectStyles, (style) => (
// just return it
createLink(`dist/${style}`)
));
// allow client to start loading js bundle
res.write(`<div id="app">`);
const endStream = readableString('');
const streams = [
styledStream,
endStream,
];
MultiStream(streams).pipe(res);
// start by piping react and styled transform stream
htmlStream.pipe(styledStream);
styledStream.on('end', () => {
res.write('</div>');
// push loaded chunks information
res.write(printDrainHydrateMarks(streamUID));
res.write('');
res.end();
});
}
toStream(): NodeJS.ReadableStream {
let flag = false;
// eslint-disable-next-line consistent-return
return multiStream(cb => {
if (flag) return cb(null, null);
flag = true;
this.toStreamAsync()
.then(stream => {
cb(null, stream);
})
.catch(error => {
cb(error, null);
});
});
}
}
createStringStream(beforeContent),
createStringStream(afterContent)
]
if (renderContent !== false) {
// Render page content to a `Stream`
// inserting this stream in the middle of `streams` array.
// `array.splice(index, 0, element)` inserts `element` at `index`.
const pageElement = React.createElement(container, containerProps, content)
streams.splice(streams.length / 2, 0, ReactDOM.renderToNodeStream(pageElement))
}
return {
route,
status,
content: combineStreams(streams),
time,
cookies: newCookies
}
}
async handler(_, h) {
const cssFiles = await globby(
testingPluginIds
? testingPluginIds.split(',').map((id) => `built_assets/css/plugins/${id}/**/*.css`)
: `built_assets/css/**/*.css`,
{ cwd: fromRoot('.'), absolute: true }
);
const stream = replacePlaceholder(
new MultiStream(cssFiles.map(path => createReadStream(path))),
'/built_assets/css/'
);
return h.response(stream).code(200).type('text/css');
}
});
return new Promise((resolve, reject) => {
try {
const nxsPackagePath = join(dirPath, 'nxs_package.json');
const filePaths = module.files.sort().map(file => join(dirPath, file));
const streams = [
normalizeFile(nxsPackagePath),
...filePaths.map(normalizeFile),
];
const hash = crypto.createHash('sha256');
hash.setEncoding('base64');
hash.on('readable', () => {
resolve(hash.read());
});
new Multistream(streams).pipe(hash);
} catch (err) {
console.error(err);
reject(err);
}
});
}
if (!module) {
const nxsPackageContent = await fs.promises.readFile(nxsPackagePath);
module = JSON.parse(nxsPackageContent);
}
const filePaths = module.files.sort().map(file => join(dirPath, file));
const streams = [
normalizeFile(nxsPackagePath),
...filePaths.map(normalizeFile),
];
const hash = crypto.createHash('sha256');
hash.setEncoding('base64');
hash.on('readable', () => {
resolve(hash.read());
});
new Multistream(streams).pipe(hash);
} catch (err) {
console.error(err);
reject(err);
}
});
}
export default function stream(tree: ReactElement) {
const doctype = new Readable();
doctype.push('');
doctype.push(null);
return multistream([doctype, renderToStaticNodeStream(tree)]);
}
count += 1;
return pipeToNewMeter(s);
}
const binaryBuffer = fs.readFileSync(target.binaryPath);
const placeholders = discoverPlaceholders(binaryBuffer);
let track = 0;
let prevStripe;
let payloadPosition;
let payloadSize;
let preludePosition;
let preludeSize;
new Multistream((cb) => {
if (count === 0) {
return cb(undefined, next(
intoStream(binaryBuffer)
));
} else
if (count === 1) {
payloadPosition = meter.bytes;
return cb(undefined, next(
intoStream(Buffer.alloc(0))
));
} else
if (count === 2) {
if (prevStripe && !prevStripe.skip) {
let { snap, store } = prevStripe;
snap = snapshotify(snap, slash);
vfs[snap][store] = [ track, meter.bytes ];