Skip to content

Commit c51cd94

Browse files
authored
fix: Close Open Handle for Empty Objects (#2338)
1 parent b641322 commit c51cd94

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/file.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,8 +2173,14 @@ class File extends ServiceObject<File, FileMetadata> {
21732173
.on('end', () => {
21742174
// In the case of an empty file no data will be received before the end event fires
21752175
if (!receivedData) {
2176-
fs.openSync(destination, 'w');
2177-
callback(null, Buffer.alloc(0));
2176+
const data = Buffer.alloc(0);
2177+
2178+
try {
2179+
fs.writeFileSync(destination, data);
2180+
callback(null, data);
2181+
} catch (e) {
2182+
callback(e as Error, data);
2183+
}
21782184
}
21792185
});
21802186
} else {

0 commit comments

Comments
 (0)