Skip to content

Commit bfaa9c2

Browse files
committed
make stream generator optional so that directories can be marked as unpacked.
1 parent 9ee3d7a commit bfaa9c2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/asar.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ export type Filestream = {
221221
*/
222222
filePath: string;
223223
/**
224-
function that returns a read stream for the file
225-
note: this is called multiple times per "file", so a new NodeJS.ReadableStream will be created each time
224+
function that returns a read stream for the file. Not utilized for directories.
225+
note: this is called multiple times per "file", so a new NodeJS.ReadableStream needs to be created each time
226226
*/
227-
streamGenerator: () => NodeJS.ReadableStream;
227+
streamGenerator?: () => NodeJS.ReadableStream;
228228
properties: {
229229
/**
230230
relative path to the symlink target
@@ -257,21 +257,27 @@ export async function createPackageFromStreams(dest: string, filestreams: Filest
257257
filesystem.insertDirectory(filename, shouldUnpack);
258258
break;
259259
case 'file':
260+
if (streamGenerator == null) {
261+
throw new Error('Stream generator is required for `file` type');
262+
}
260263
files.push({
261264
filename,
262-
streamGenerator,
265+
streamGenerator: streamGenerator!,
263266
link: undefined,
264267
mode: stat.mode,
265268
unpack: shouldUnpack,
266269
});
267-
return filesystem.insertFile(filename, streamGenerator, shouldUnpack, {
270+
return filesystem.insertFile(filename, streamGenerator!, shouldUnpack, {
268271
type: 'file',
269272
stat,
270273
});
271274
case 'link':
275+
if (streamGenerator == null) {
276+
throw new Error('Stream generator is required for `link` type');
277+
}
272278
links.push({
273279
filename,
274-
streamGenerator,
280+
streamGenerator: streamGenerator!,
275281
link: symlink,
276282
mode: stat.mode,
277283
unpack: shouldUnpack,

0 commit comments

Comments
 (0)