Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function exportFile(file, done) {
console.log('-- downloading %s', file.name)
const { id, name } = file
const tmpFile = path.join(__dirname, '.drive', TMP_DIRNAME, name)
const dest = fs.createWriteStream(tmpFile)
const request = drive.files.export({ auth, fileId: id, mimeType: REQUEST_MIMETYPE })
.pipe(stripBomStream())
.pipe(dest)
request.on('finish', () => {
const fpath = path.join(path.dirname(tmpFile), name)
// pass `content` to user-defined middleware in case further any
// intermediate transforms need to take place. default is a simple pass-
// through
const content = transformWithMiddleware(fs.readFileSync(tmpFile, 'utf8')/*, contentType */)
fs.writeFile(fpath, content, err => {
done(err, file)
})
})
request.on('error', done)
}
async getFileAsStream(relativeFilePath, { encoding } = { encoding: 'utf8' }) {
const filePath = await this.getPath(relativeFilePath);
const readStream = createReadStream(filePath, {
autoClose: true,
encoding,
flags: 'r',
});
return !encoding ? readStream : readStream.pipe(stripBomStream());
}
zipfile.openReadStream(this.files[path], (err, readStream) => {
if (err) {
return reject(err);
}
return resolve(readStream.pipe(stripBomStream()));
});
});