import pako from 'pako' ; import { MethodNotImplementedError } from 'src/core/errors' ; import PDFDict from 'src/core/objects/PDFDict' ; import PDFName from 'src/core/objects/PDFName' ; import PDFStream from 'src/core/objects/PDFStream' ; import { Cache } from 'src/utils' ; class PDFFlateStream extends PDFStream { protected readonly contentsCache : Cache < Uint8Array > ; protected readonly encode : boolean ; constructor ( dict , encode ) { super ( dict ) ; this . encode = encode ; if ( encode ) dict . set ( PDFName . of ( 'Filter' ) , PDFName . of ( 'FlateDecode' ) ) ; this . contentsCache = Cache . populatedBy ( this . computeContents ) ; } computeContents = ( ) : Uint8Array => { const unencodedContents = this . getUnencodedContents ( ) ; return this . encode ? pako . deflate ( unencodedContents ) : unencodedContents ; } ; getContents ( ) { return this . contentsCache . access ( ) ; } getContentsSize ( ) { return this . contentsCache . access ( ) . length ; } getUnencodedContents ( ) { throw new MethodNotImplementedError ( this . constructor . name , 'getUnencodedContents' ) ; } } export default PDFFlateStream ;