summaryrefslogtreecommitdiff
path: root/internal/io
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2021-08-28 20:26:32 +0100
committerPaul Buetow <paul@buetow.org>2021-08-28 20:28:34 +0100
commit23982f331c2154a66b86d596226c24454fd06be5 (patch)
treef8aa72eb5110a4de914f28a063b528fd166a3a6b /internal/io
parent8c2e94030d0e31289c35fcfb56499707fd4a7ccd (diff)
1. Major performance gain by not checking for file truncation aftter
each bytes read. 2. Introduce field separator to the protocol package.
Diffstat (limited to 'internal/io')
-rw-r--r--internal/io/fs/readfile.go20
1 files changed, 9 insertions, 11 deletions
diff --git a/internal/io/fs/readfile.go b/internal/io/fs/readfile.go
index e44f30e..f2f672a 100644
--- a/internal/io/fs/readfile.go
+++ b/internal/io/fs/readfile.go
@@ -157,22 +157,21 @@ func (f readFile) read(ctx context.Context, fd *os.File, rawLines chan *bytes.Bu
message := pool.BytesBuffer.Get().(*bytes.Buffer)
for {
- select {
- case <-ctx.Done():
- return nil
- case <-truncate:
- if isTruncated, err := f.truncated(fd); isTruncated {
- return err
- }
- default:
- }
-
b, err := reader.ReadByte()
if err != nil {
if err != io.EOF {
return err
}
+ select {
+ case <-truncate:
+ if isTruncated, err := f.truncated(fd); isTruncated {
+ return err
+ }
+ case <-ctx.Done():
+ return nil
+ default:
+ }
if !f.seekEOF {
logger.Info(f.FilePath(), "End of file reached")
return nil
@@ -207,7 +206,6 @@ func (f readFile) read(ctx context.Context, fd *os.File, rawLines chan *bytes.Bu
select {
case rawLines <- message:
message = pool.BytesBuffer.Get().(*bytes.Buffer)
- //fmt.Printf("%d %d %p\n", message.Len(), message.Cap(), message)
case <-ctx.Done():
return nil
}