C
C
Coder3212017-08-30 22:19:50
JavaScript
Coder321, 2017-08-30 22:19:50

How to pause/resume for streaming?

There is a simple endpoint that returns a large file:

app.get('/', (req, res) => {
    const filePath = req.app.get('filePath');
    const stream = createReadStream(resolve(filePath, smallFile));
    res.writeHead(200, {
        'content-type': mime.lookup(stream.path)
    });
    stream.on('error', res.end());
    stream.on('close', res.end());
    stream.pipe(res);
});

I need to create another endpoint for pause/resume this stream, but I can't figure out how to do it yet. Let's say I can push all created streams into an array, but how do I know which stream needs to pause/resume? As a solution, you need to assign some kind of ID to each stream, but how to give it to the front?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question