Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 6 buffer problem #9

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ Output :
(...)
```


## What if i get an error: "nothing on stdout"

The reason might be when the token buffer is overflowed.

Try to increase the buffer size using function as a parameter by NewExiftool initialization:

```go
et, err = exiftool.NewExiftool(func(ex *exiftool.Exiftool) error {
ex.SetBufferSize(4064 * 1024)
return nil
})

if err != nil {
fmt.Printf("Error when intializing: %v\n", err)
return
}
defer et.Close()
```

## Changelog

- v1.1.0 : initial release
Expand Down
16 changes: 12 additions & 4 deletions exiftool.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ var ErrNotExist = errors.New("file does not exist")

// Exiftool is the exiftool utility wrapper
type Exiftool struct {
lock sync.Mutex
stdin io.WriteCloser
stdout io.ReadCloser
scanout *bufio.Scanner
lock sync.Mutex
stdin io.WriteCloser
stdout io.ReadCloser
scanout *bufio.Scanner
bufferSize int
}

// NewExiftool instanciates a new Exiftool with configuration functions. If anything went
Expand All @@ -55,6 +56,8 @@ func NewExiftool(opts ...func(*Exiftool) error) (*Exiftool, error) {
}

e.scanout = bufio.NewScanner(e.stdout)
buf := make([]byte, 0, 64*1024)
e.scanout.Buffer(buf, e.bufferSize)
e.scanout.Split(splitReadyToken)

if err = cmd.Start(); err != nil {
Expand All @@ -64,6 +67,11 @@ func NewExiftool(opts ...func(*Exiftool) error) (*Exiftool, error) {
return &e, nil
}

// SetBufferSize changes the buffer size
func (e *Exiftool) SetBufferSize(size int) {
Copy link
Owner

Choose a reason for hiding this comment

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

I think that the buffer size specification should rather be specified as a functionnal options.

The thing that bothers me with this implementation (a method on the ExifTool struct) is that users could think that the buffer size could be set after ExifTool initiatialization, but it doesn't.

Could you please change your implementation to fit a functionnal option (func WithBufferSize func(*Exiftool) error { ... }) ? The NewExifTool function already accepts functionnal options.

Copy link
Owner

Choose a reason for hiding this comment

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

I don't mention unit-tests and the update of the documentation :)

e.bufferSize = size
}

// Close closes exiftool. If anything went wrong, a non empty error will be returned
func (e *Exiftool) Close() error {
e.lock.Lock()
Expand Down