Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function saveFileStream(
rs: ReadableStream,
fileName: string,
): Promise {
const fileStream = createWriteStream(fileName);
const writer = fileStream.getWriter();
// Feature detection for pipeTo (more efficient)
if (rs.pipeTo) {
// like as we never did fileStream.getWriter()
writer.releaseLock();
return rs.pipeTo(fileStream);
}
const reader = rs.getReader();
const pump = (): Promise =>
reader.read().then(({ value, done }) =>
done
// Close the stream so we stop writing
? writer.close()
// Write one chunk, then get the next one
function saveFileStream(rs, fileName) {
const fileStream = createWriteStream(fileName);
const writer = fileStream.getWriter();
// Feature detection for pipeTo (more efficient)
if (rs.pipeTo) {
// like as we never did fileStream.getWriter()
writer.releaseLock();
return rs.pipeTo(fileStream);
}
const reader = rs.getReader();
const pump = () =>
reader.read().then(({ value, done }) =>
done
? // close the stream so we stop writing
writer.close()
: // Write one chunk, then get the next one
function saveFileStream(rs, fileName) {
var fileStream = streamsaver_1.createWriteStream(fileName);
var writer = fileStream.getWriter();
// Feature detection for pipeTo (more efficient)
if (rs.pipeTo) {
// like as we never did fileStream.getWriter()
writer.releaseLock();
return rs.pipeTo(fileStream);
}
var reader = rs.getReader();
var pump = function () {
return reader.read().then(function (_a) {
var value = _a.value, done = _a.done;
return done
// Close the stream so we stop writing
? writer.close()
// Write one chunk, then get the next one
: writer.write(value).then(pump);
downloadLogAsCSV() {
console.log('downloadLogAsCSV:start');
const { dbcFilename } = this.state;
const fileStream = createWriteStream(
`${dbcFilename.replace(/\.dbc/g, '-')}${+new Date()}.csv`
);
const writer = fileStream.getWriter();
const encoder = new TextEncoder();
if (this.state.live) {
return this.downloadLiveLogAsCSV(dataHandler);
}
return this.downloadRawLogAsCSV(dataHandler);
function dataHandler(e) {
const { logData, shouldClose, progress } = e.data;
if (shouldClose) {
console.log('downloadLogAsCSV:close');
writer.close();
return;
const downloadFile = gif => {
const filename = getFilename(gif)
const fileStream = streamSaver.createWriteStream(filename, gif.src.length)
const writer = fileStream.getWriter()
const data = new ImageDataConverter(gif.src).convertToTypedArray()
writer.write(data)
writer.close()
}