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

Response stream events? #119

Open
devskope opened this issue Sep 15, 2020 · 0 comments
Open

Response stream events? #119

devskope opened this issue Sep 15, 2020 · 0 comments

Comments

@devskope
Copy link

devskope commented Sep 15, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant