Skip to content

Response stream events? #119

@devskope

Description

@devskope

I am trying to sequentially archive (using node-archiver) a couple of remote files fetched using bent:

const appendTracks = async (archive, items) => {
 items.forEach(async (item) => {
    const beatStream = await bent(item.publicUrl)();         // mp3s **

    archive.append(beatStream, { name: item.name });

     // ********** the following doesn't seem to work ****************
    await new Promise((resolve, reject) => {
      beatStream.on('end', () => {   // is this even possible ??? 🤷🏻‍♂️
        resolve();
      });
      
      beatStream.on('error', (err) => {
        reject();
       });
    });
  });
};

archive.pipe(res);
appendTracks(archive, order.items).then(() => archive.finalize());

How do I ensure one stream is done before the next download begins?
Need to guarantee that archive.finalize() isn't fired prematurely, which is what is happening right now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions