-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thumbnails: extract pictures from audio files
- Loading branch information
Showing
23 changed files
with
3,167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package preprocessor | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
type LazyReadSeeker struct { | ||
reader io.Reader | ||
buffer []byte | ||
position int64 | ||
} | ||
|
||
func NewLazyReadSeeker(r io.Reader) *LazyReadSeeker { | ||
return &LazyReadSeeker{ | ||
reader: r, | ||
buffer: make([]byte, 0), | ||
} | ||
} | ||
|
||
func (l *LazyReadSeeker) Read(p []byte) (int, error) { | ||
// Fill buffer if necessary | ||
if l.position >= int64(len(l.buffer)) { | ||
temp := make([]byte, len(p)) | ||
n, err := l.reader.Read(temp) | ||
if err != nil && err != io.EOF { | ||
return 0, err | ||
} | ||
if n == 0 { | ||
return 0, io.EOF | ||
} | ||
l.buffer = append(l.buffer, temp[:n]...) | ||
} | ||
|
||
// Read from buffer | ||
n := copy(p, l.buffer[l.position:]) | ||
l.position += int64(n) | ||
|
||
return n, nil | ||
} | ||
|
||
func (l *LazyReadSeeker) Seek(offset int64, whence int) (int64, error) { | ||
var newPos int64 | ||
switch whence { | ||
case io.SeekStart: | ||
newPos = offset | ||
case io.SeekCurrent: | ||
newPos = l.position + offset | ||
default: | ||
return 0, errors.New("seekEnd is not supported") | ||
} | ||
|
||
if newPos < 0 { | ||
return 0, errors.New("negative position is invalid") | ||
} | ||
|
||
l.position = newPos | ||
return l.position, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.