mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-01 22:17:29 +08:00
Hack to suppress EOF errors when parsing PDF fragments in font_test.go
This commit is contained in:
parent
5c2448d09f
commit
a27c6bbf90
@ -52,6 +52,9 @@ type PdfParser struct {
|
||||
// the length reference (if not object) prior to reading the actual stream. This has risks of endless looping.
|
||||
// Tracking is necessary to avoid recursive loops.
|
||||
streamLengthReferenceLookupInProgress map[int64]bool
|
||||
|
||||
// Hack to allow parsing of PDF fragments without reporting an EOF error.
|
||||
suppressEOF bool
|
||||
}
|
||||
|
||||
// PdfVersion returns version of the PDF file.
|
||||
@ -1322,7 +1325,9 @@ func (parser *PdfParser) ParseIndirectObject() (PdfObject, error) {
|
||||
common.Log.Trace("-Read indirect obj")
|
||||
bb, err := parser.reader.Peek(20)
|
||||
if err != nil {
|
||||
common.Log.Debug("ERROR: Fail to read indirect obj")
|
||||
if !(parser.suppressEOF && err == io.EOF) {
|
||||
common.Log.Debug("ERROR: Fail to read indirect obj. err=%v", err)
|
||||
}
|
||||
return &indirect, err
|
||||
}
|
||||
common.Log.Trace("(indirect obj peek \"%s\"", string(bb))
|
||||
@ -1493,7 +1498,7 @@ func (parser *PdfParser) ParseIndirectObject() (PdfObject, error) {
|
||||
// For testing purposes.
|
||||
// TODO: Unexport (v3) or move to test files, if needed by external test cases.
|
||||
func NewParserFromString(txt string) *PdfParser {
|
||||
parser := PdfParser{}
|
||||
parser := PdfParser{suppressEOF: true}
|
||||
buf := []byte(txt)
|
||||
|
||||
bufReader := bytes.NewReader(buf)
|
||||
|
Loading…
x
Reference in New Issue
Block a user