Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(example): drive export end before finish writing the file #1798

Merged
merged 3 commits into from Sep 12, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 24 additions & 11 deletions samples/drive/export.js
Expand Up @@ -33,18 +33,31 @@ async function runSample() {
{fileId, mimeType: 'application/pdf'},
{responseType: 'stream'}
);
await new Promise((resolve, reject) => {
res.data
.on('end', () => {
console.log(`Done downloading document: ${destPath}.`);
resolve();
await Promise.all([
new Promise((resolve, reject) => {
res.data
.on('end', () => {
resolve();
})
.on('error', err => {
console.error('Error downloading document.');
reject(err);
})
.pipe(dest);
}),
new Promise((resolve, reject) => {
dest
.on('finish', () => {
console.log(`Done downloading document: ${destPath}.`);
resolve();
})
.on('error', err => {
console.error('Error saving document.');
reject(err);
})
})
.on('error', err => {
console.error('Error downloading document.');
reject(err);
})
.pipe(dest);
});
])
}
// [END main_body]
}

Expand Down