fix wrong git ignore
This commit is contained in:
44
internal/pdf/core/io.go
Normal file
44
internal/pdf/core/io.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"gitea.tecamino.com/paadi/pdfmerge/internal/pdf/common"
|
||||
)
|
||||
|
||||
// ReadAtLeast reads at least n bytes into slice p.
|
||||
// Returns the number of bytes read (should always be == n), and an error on failure.
|
||||
// TODO (v3): Unexport.
|
||||
func (parser *PdfParser) ReadAtLeast(p []byte, n int) (int, error) {
|
||||
remaining := n
|
||||
start := 0
|
||||
numRounds := 0
|
||||
for remaining > 0 {
|
||||
nRead, err := parser.reader.Read(p[start:])
|
||||
if err != nil {
|
||||
common.Log.Debug("error Failed reading (%d;%d) %s", nRead, numRounds, err.Error())
|
||||
return start, errors.New("failed reading")
|
||||
}
|
||||
numRounds++
|
||||
start += nRead
|
||||
remaining -= nRead
|
||||
}
|
||||
return start, nil
|
||||
}
|
||||
|
||||
// Get the current file offset, accounting for buffered position.
|
||||
// TODO (v3): Unexport.
|
||||
func (parser *PdfParser) GetFileOffset() int64 {
|
||||
offset, _ := parser.rs.Seek(0, os.SEEK_CUR)
|
||||
offset -= int64(parser.reader.Buffered())
|
||||
return offset
|
||||
}
|
||||
|
||||
// Seek the file to an offset position.
|
||||
// TODO (v3): Unexport.
|
||||
func (parser *PdfParser) SetFileOffset(offset int64) {
|
||||
parser.rs.Seek(offset, os.SEEK_SET)
|
||||
parser.reader = bufio.NewReader(parser.rs)
|
||||
}
|
||||
Reference in New Issue
Block a user