Skip to content

Commit

Permalink
fix: Close Open Handle for Empty Objects (#2338)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-goog authored Oct 20, 2023
1 parent b641322 commit c51cd94
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2173,8 +2173,14 @@ class File extends ServiceObject<File, FileMetadata> {
.on('end', () => {
// In the case of an empty file no data will be received before the end event fires
if (!receivedData) {
fs.openSync(destination, 'w');
callback(null, Buffer.alloc(0));
const data = Buffer.alloc(0);

try {
fs.writeFileSync(destination, data);
callback(null, data);
} catch (e) {
callback(e as Error, data);
}
}
});
} else {
Expand Down

0 comments on commit c51cd94

Please sign in to comment.