@@ -155,6 +155,9 @@ const loadPdf = async pdf => {
155155 pdfViewer . setDocument ( pdfDocument ) ;
156156
157157 pdfDocument . getMetadata ( ) . then ( metadata => {
158+ if ( metadata . contentLength === null ) {
159+ metadata . contentLength = options . data . length ;
160+ }
158161 loadMetadata ( el , pdfViewer , metadata ) ;
159162 } ) ;
160163
@@ -208,7 +211,7 @@ const loadMetadata = (el, pdfViewer, metadata) => {
208211 }
209212
210213 const filesize = el . querySelector ( '.bb-view-pdf-dialog-file-size' ) ;
211- filesize . textContent = getFilesize ( metadata ) ;
214+ filesize . textContent = getFileSize ( metadata ) ;
212215
213216 const title = el . querySelector ( '.bb-view-pdf-dialog-title' ) ;
214217 const author = el . querySelector ( '.bb-view-pdf-dialog-author' ) ;
@@ -291,20 +294,26 @@ function parsePdfDate(pdfDateString) {
291294 return date ;
292295}
293296
294- const getFilesize = metadata => {
297+ const getFileSize = metadata => {
295298 const length = metadata . contentLength ;
299+ let val = 0 ;
300+ let unit = 'B' ;
296301 if ( length < 1024 ) {
297- return ` ${ Math . round ( length ) } B` ;
302+ val = length ;
298303 }
299304 else if ( length < 1024 * 1024 ) {
300- return `${ Math . round ( length / 1024 ) } KB` ;
305+ unit = 'KB' ;
306+ val = length / 1024 ;
301307 }
302308 else if ( length < 1024 * 1024 * 1024 ) {
303- return `${ length / 1024 / 1024 } MB` ;
309+ unit = 'MB' ;
310+ val = length / 1024 / 1024 ;
304311 }
305312 else if ( length < 1024 * 1024 * 1024 * 1024 ) {
306- return `${ length / 1024 / 1024 / 1024 } GB` ;
313+ unit = 'GB' ;
314+ val = length / 1024 / 1024 / 1024 ;
307315 }
316+ return `${ Math . round ( val * 100 ) / 100 } ${ unit } ` ;
308317}
309318
310319const setObserver = el => {
0 commit comments