@@ -14,11 +14,6 @@ type PdfResult = {
14
14
filename : string ;
15
15
} ;
16
16
17
- type ZipResult = {
18
- dataStream : NodeJS . ReadableStream ;
19
- filename : string ;
20
- } ;
21
-
22
17
type ConstructorProps = {
23
18
browser : Browser ;
24
19
contentService : CmsArchiveContentService ;
@@ -52,10 +47,9 @@ export class PdfGenerator {
52
47
53
48
const zipFilename = `${ newestVersion . name } _${ newestVersion . meta . timestamp } -${ oldestVersion . meta . timestamp } .zip` ;
54
49
55
- res . setHeader ( 'Content-Disposition' , `attachment; filename="${ zipFilename } "` ) . setHeader (
56
- 'Content-Type' ,
57
- mime . lookup ( zipFilename ) || 'application/octet-stream'
58
- ) ;
50
+ res . setHeader ( 'Content-Disposition' , `attachment; filename="${ zipFilename } "` )
51
+ . setHeader ( 'Content-Type' , mime . lookup ( zipFilename ) || 'application/octet-stream' )
52
+ . setHeader ( 'Transfer-Encoding' , 'chunked' ) ;
59
53
60
54
const archive = archiver ( 'zip' ) ;
61
55
@@ -77,6 +71,12 @@ export class PdfGenerator {
77
71
return ;
78
72
}
79
73
74
+ if ( ! res . headersSent ) {
75
+ // Set an estimate for content-length, which allows clients to track the download progress
76
+ // This header is not according to spec for chunked responses, but browsers seem to respect it
77
+ res . setHeader ( 'Content-Length' , pdf . length * contentVersions . length ) ;
78
+ }
79
+
80
80
const fileName = this . getPdfFilename ( content ) ;
81
81
82
82
archive . append ( pdf , { name : fileName } ) ;
0 commit comments