Skip to content

Commit

Permalink
fix: setting sourceFile on the reader when importing streams
Browse files Browse the repository at this point in the history
fixes a bug where it wasn't possible to import from more than one stream at a time
  • Loading branch information
johan-lejdung authored and phpdave11 committed Mar 30, 2024
1 parent 1f10f98 commit 828e193
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (this *Importer) SetSourceStream(rs *io.ReadSeeker) {
this.sourceFile = fmt.Sprintf("%v", rs)

if _, ok := this.readers[this.sourceFile]; !ok {
reader, err := NewPdfReaderFromStream(*rs)
reader, err := NewPdfReaderFromStream(this.sourceFile, *rs)
if err != nil {
panic(err)
}
Expand Down
7 changes: 4 additions & 3 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"compress/zlib"
"encoding/binary"
"fmt"
"github.com/pkg/errors"
"io"
"io/ioutil"
"math"
"os"
"strconv"

"github.com/pkg/errors"
)

type PdfReader struct {
Expand All @@ -31,12 +32,12 @@ type PdfReader struct {
pageCount int
}

func NewPdfReaderFromStream(rs io.ReadSeeker) (*PdfReader, error) {
func NewPdfReaderFromStream(sourceFile string, rs io.ReadSeeker) (*PdfReader, error) {
length, err := rs.Seek(0, 2)
if err != nil {
return nil, errors.Wrapf(err, "Failed to determine stream length")
}
parser := &PdfReader{f: rs, nBytes: length}
parser := &PdfReader{f: rs, sourceFile: sourceFile, nBytes: length}
if err := parser.init(); err != nil {
return nil, errors.Wrap(err, "Failed to initialize parser")
}
Expand Down

1 comment on commit 828e193

@dekiftw
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phpdave11 Could you please make a new release with this fix? Thanks!

Please sign in to comment.