title: Angular HTTP client how to know when a chunked download request finished?
body: <p>I am using angular <a href="https://angular.io/guide/http" rel="nofollow noreferrer">HttpClient</a> to download an <code>arraybuffer</code>, the server is sending the data with the following headers:</p>
  <p>*<em>To prevent confusion, the download route basically downloads a chunk file saved in the cloud, but the download itself sends the chunk in chunks</em></p>
  <p>That's the backend part written in NestJS which is a framework on top of Express:</p>
  <pre><code>@Get(`chunk/:fileKey/:startBytes/:endBytes`)
  public async download(@Req() req, @Res() res,
                        @Param('fileKey') fileKey: string,
                        @Param('startBytes') startBytes: number,
                        @Param('endBytes') endBytes: number) {
  
      res.setHeader(&quot;content-type&quot;, &quot;application/octet-stream&quot;);
      res.setHeader(&quot;Content-Transfer-Encoding&quot;, &quot;binary&quot;);
      res.setHeader(&quot;Cache-Control&quot;, &quot;private&quot;);
      res.setHeader(&quot;Cache-Control&quot;, &quot;no-store&quot;);
      res.setHeader(&quot;Content-Disposition&quot;, &quot;attachment&quot;);
  
      const downloadRequest: DownloadChunkDto = {
          fileKey,
          startBytes,
          endBytes
      };
  
      const stream = await this.fileTransferProvider.getChunkDownload(req.sessionObject.id, downloadRequest);
      stream.pipe(res);
  }
  </code></pre>
  <p>I load the file using my provider that provides that functionality and passes the stream to the response of express.</p>
  <p>And I download it with this:</p>
  <pre><code>this.http.request(httpRequest).subscribe((data) =&gt; {
    console.log('chunk received!', data);
  });
  </code></pre>
  <p>I receive the chunks, but I cannot know when the process has finished. Tried using <code>finalize</code> as pipe, and it's called every time a chunk is sent.</p>
  <p>In the network tab, I see a separated request for each chunk sent as well, so I am not really sure if this is possible without making the server tell the client when the stream has ended</p>