Skip to content

Commit

Permalink
Fix #481 Add Rene Kaufmann to contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
hhrutter committed Feb 22, 2023
1 parent de1d264 commit d26377a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Thanks goes to these wonderful people:
| [<img src="https://avatars2.githubusercontent.com/u/1175110?s=400&v=4" width="100px"/><br/><sub><b>Dmitry Harnitski</b></sub>](https://github.com/dharnitski) | [<img src="https://avatars0.githubusercontent.com/u/1074083?s=400&v=4" width="100px"/><br/><sub><b>ryarnyah</b></sub>](https://github.com/ryarnyah) | [<img src="https://avatars0.githubusercontent.com/u/13267?s=400&v=4" width="100px"/><br/><sub><b>Sam Giffney</b></sub>](https://github.com/s01ipsist) | [<img src="https://avatars3.githubusercontent.com/u/32948066?s=400&v=4" width="100px"/><br /><sub><b>Carlos Eduardo Witte</b></sub>](https://github.com/cewitte) | [<img src="https://avatars1.githubusercontent.com/u/2374948?s=400&u=a36e5f8da8dc1c102bc4d283f25e4c61cae7f985&v=4" width="100px"/><br/><sub><b>minusworld</b></sub>](https://github.com/minusworld) | [<img src="https://avatars0.githubusercontent.com/u/18538487?s=400&u=b9e628dfc60f672a887be2ed04a791195829943e&v=4" width="100px"/><br/><sub><b>Witold Konior</b></sub>](https://github.com/jozuenoon) | [<img src="https://avatars0.githubusercontent.com/u/630151?s=400&v=4" width="100px"/><br/><sub><b>joonas.fi</b></sub>](https://github.com/joonas-fi) |
| [<img src="https://avatars3.githubusercontent.com/u/10349817?s=400&u=93bacb23bd2909d5b6c5b644a8d4cdd947422ee1&v=4" width="100px"/><br/><sub><b>Henrik Reinstädtler</b></sub>](https://github.com/henrixapp) | [<img src="https://avatars1.githubusercontent.com/u/72016286?s=400&v=4" width="100px"/><br/><sub><b>VMorozov-wh</b></sub>](https://github.com/VMorozov-wh) | [<img src="https://avatars0.githubusercontent.com/u/31929422?s=400&v=4" width="100px"/><br/><sub><b>Benoit KUGLER</b></sub>](https://github.com/benoitkugler) | [<img src="https://avatars.githubusercontent.com/u/704919?s=400&v=4" width="100px"/><br/><sub><b>Adam Greenhall</b></sub>](https://github.com/adamgreenhall) | [<img src="https://avatars.githubusercontent.com/u/5201812?s=400&u=8a0a9fca4560be71d4923299ddebf877854eea54&v=4" width="100px"/><br/><sub><b>moritamori</b></sub>](https://github.com/moritamori) | [<img src="https://avatars.githubusercontent.com/u/41904529?s=400&u=044396494285ad806e86d1936c390b3071ce57c0&v=4" width="100px"/><br/><sub><b>JanBaryla</b></sub>](https://github.com/JanBaryla) | [<img src="https://avatars.githubusercontent.com/u/43145244?s=400&u=89a689f1a854ce0f57ae2a0333c82bfdc5723bb9&v=4" width="100px"/><br/><sub><b>TheDiscordian</b></sub>](https://github.com/TheDiscordian) |
| [<img src="https://avatars.githubusercontent.com/u/15472552?v=4" width="100px"/><br/><sub><b>Rafael Garcia Argente</b></sub>](https://github.com/rgargente) | [<img src="https://avatars.githubusercontent.com/u/710057?v=4" width="100px"/><br/><sub><b>truyet</b></sub>](https://github.com/truyet) | [<img src="https://avatars.githubusercontent.com/u/5031217?v=4" width="100px"/><br/><sub><b>Christian Nicola</b></sub>](https://github.com/christiannicola) | [<img src="https://avatars.githubusercontent.com/u/3233970?v=4" width="100px"/><br/><sub><b>Benjamin Krill</b></sub>](https://github.com/kben) | [<img src="https://avatars.githubusercontent.com/u/26521615?v=4" width="100px"/><br/><sub><b>Peter Wyatt</b></sub>](https://github.com/petervwyatt) | [<img src="https://avatars.githubusercontent.com/u/3142701?v=4" width="100px"/><br/><sub><b>Kroum Tzanev</b></sub>](https://github.com/kpym) | [<img src="https://avatars.githubusercontent.com/u/992878?v=4" width="100px"/><br/><sub><b>Stefan Huber</b></sub>](https://github.com/signalwerk)|
| [<img src="https://avatars.githubusercontent.com/u/59667587?v=4" width="100px"/><br/><sub><b>Juan Iscar</b></sub>](https://github.com/juaismar) | [<img src="https://avatars.githubusercontent.com/u/20135478?v=4" width="100px"/><br/><sub><b>Eng Zer Jun</b></sub>](https://github.com/Juneezee) | [<img src="https://avatars.githubusercontent.com/u/28459131?v=4" width="100px"/><br/><sub><b>Dmitry Ivanov</b></sub>](https://github.com/hant0508)|||||
| [<img src="https://avatars.githubusercontent.com/u/59667587?v=4" width="100px"/><br/><sub><b>Juan Iscar</b></sub>](https://github.com/juaismar) | [<img src="https://avatars.githubusercontent.com/u/20135478?v=4" width="100px"/><br/><sub><b>Eng Zer Jun</b></sub>](https://github.com/Juneezee) | [<img src="https://avatars.githubusercontent.com/u/28459131?v=4" width="100px"/><br/><sub><b>Dmitry Ivanov</b></sub>](https://github.com/hant0508)|[<img src="https://avatars.githubusercontent.com/u/16866547?v=4" width="100px"/><br/><sub><b>Rene Kaufmann</b></sub>](https://github.com/HeavyHorst)||||

<!-- ALL-CONTRIBUTORS-LIST:END - Do not remove or modify this section -->

Expand Down
47 changes: 33 additions & 14 deletions pkg/pdfcpu/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@ func Read(rs io.ReadSeeker, conf *model.Configuration) (*model.Context, error) {
return ctx, nil
}

// fillBuffer reads from r until buf is full or read returns an error.
// Unlike io.ReadAtLeast fillBuffer does not return ErrUnexpectedEOF
// if an EOF happens after reading some but not all the bytes.
// Special thanks go to Rene Kaufmann.
func fillBuffer(r io.Reader, buf []byte) (int, error) {
var n int
var err error

for n < len(buf) && err == nil {
var nn int
nn, err = r.Read(buf[n:])
n += nn
}

if n > 0 && err == io.EOF {
return n, nil
}

return n, err
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one carriage return followed
Expand Down Expand Up @@ -215,7 +236,7 @@ func offsetLastXRefSection(ctx *model.Context, skip int64) (*int64, error) {

curBuf := make([]byte, bufSize)

_, err = rs.Read(curBuf)
_, err = fillBuffer(rs, curBuf)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -767,7 +788,7 @@ func scanForPreviousXref(ctx *model.Context, offset *int64) *int64 {

curBuf := make([]byte, bufSize)

n, err := rd.Read(curBuf)
n, err := fillBuffer(rd, curBuf)
if err != nil {
return nil
}
Expand Down Expand Up @@ -1118,7 +1139,7 @@ func headerVersion(rs io.ReadSeeker, headerBufSize int) (v *model.Version, eolCo
}

buf := make([]byte, headerBufSize)
n, err := rs.Read(buf)
n, err := fillBuffer(rs, buf)
if err != nil {
return nil, 0, err
}
Expand Down Expand Up @@ -1421,7 +1442,7 @@ func growBufBy(buf []byte, size int, rd io.Reader) ([]byte, error) {

b := make([]byte, size)

_, err := rd.Read(b)
_, err := fillBuffer(rd, b)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1970,15 +1991,15 @@ func readStreamContent(rd io.Reader, streamLength int) ([]byte, error) {

log.Read.Printf("readStreamContent: begin streamLength:%d\n", streamLength)

// If streamLength == 0 read until "endstream" then fix "Length"
if streamLength == 0 {
// Read until "endstream" then fix "Length".
return readStreamContentBlindly(rd)
}

buf := make([]byte, streamLength)

for totalCount := 0; totalCount < streamLength; {
count, err := rd.Read(buf[totalCount:])
count, err := fillBuffer(rd, buf[totalCount:])
if err != nil {
if err != io.EOF {
return nil, err
Expand All @@ -1994,22 +2015,21 @@ func readStreamContent(rd io.Reader, streamLength int) ([]byte, error) {

log.Read.Printf("readStreamContent: count=%d, buflen=%d(%X)\n", count, len(buf), len(buf))
totalCount += count

}

log.Read.Printf("readStreamContent: end\n")

return buf, nil
}

// LoadEncodedStreamContent loads the encoded stream content from file into StreamDict.
// LoadEncodedStreamContent loads the encoded stream content into sd.
func loadEncodedStreamContent(ctx *model.Context, sd *types.StreamDict) ([]byte, error) {

log.Read.Printf("LoadEncodedStreamContent: begin\n%v\n", sd)

var err error

// Return saved decoded content.
// Return already available decoded content.
if sd.Raw != nil {
log.Read.Println("LoadEncodedStreamContent: end, already in memory.")
return sd.Raw, nil
Expand Down Expand Up @@ -2038,8 +2058,7 @@ func loadEncodedStreamContent(ctx *model.Context, sd *types.StreamDict) ([]byte,

log.Read.Printf("LoadEncodedStreamContent: seeked to offset:%d\n", newOffset)

// Buffer stream contents.
// Read content from disk.
// Read content bytes.
rawContent, err := readStreamContent(rd, int(*sd.StreamLength))
if err != nil {
return nil, err
Expand Down Expand Up @@ -2386,19 +2405,19 @@ func dereferenceObject(ctx *model.Context, objNr int) error {

o := entry.Object

// Already dereferenced object.
if o != nil {
// Already dereferenced.
logStream(entry.Object)
updateBinaryTotalSize(ctx, o)
log.Read.Printf("handleCachedStreamDict: using cached object %d of %d\n<%s>\n", objNr, xRefTableSize, entry.Object)
return nil
}

// Dereference (load from disk into memory).
// Dereference.

log.Read.Printf("dereferenceObject: dereferencing object %d\n", objNr)

// Parse object from file: anything goes dict, array, integer, float, streamdicts...
// Parse object from ctx: anything goes dict, array, integer, float, streamdict...
o, err := ParseObject(ctx, *entry.Offset, objNr, *entry.Generation)
if err != nil {
return errors.Wrapf(err, "dereferenceObject: problem dereferencing object %d", objNr)
Expand Down

0 comments on commit d26377a

Please sign in to comment.