async getFileData(filename) { const bucket = await this._getBucket(); const stream = bucket.openDownloadStreamByName(filename); stream.read(); return new Promise((resolve, reject) => { const chunks = []; stream.on('data', data => { chunks.push(data); }); stream.on('end', () => { const data = Buffer.concat(chunks); if (this._fileKey !== null) { const authTagLocation = data.length - 16; const ivLocation = data.length - 32; const authTag = data.slice(authTagLocation); const iv = data.slice(ivLocation, authTagLocation); const encrypted = data.slice(0, ivLocation); const decipher = crypto.createDecipheriv(this._algorithm, this._fileKey, iv); decipher.setAuthTag(authTag); return resolve(Buffer.concat([decipher.update(encrypted), decipher.final()])); } resolve(data); }); stream.on('error', err => { reject(err); }); }); }
'Content-Type': contentType }); const stream = bucket.openDownloadStreamByName(filename); stream.start(start); stream.on('data', chunk => {
'Content-Type': contentType, }); const stream = bucket.openDownloadStreamByName(filename); stream.start(start); stream.on('data', (chunk) => {
async getFileData(filename: string) { const bucket = await this._getBucket(); const stream = bucket.openDownloadStreamByName(filename); stream.read(); return new Promise((resolve, reject) => {