1
0
Fork 0

Refactor to make more use of `progress` module

master
Philip O'Toole 9 months ago
parent c7d378b5c6
commit 63e3f8c80f

@ -2,6 +2,7 @@
### New features
- [PR #1563](https://github.com/rqlite/rqlite/pull/1563): Support S3-compatible storage systems for auto-backups and auto-restores. Fixes issue [#1560](https://github.com/rqlite/rqlite/issues/1560). Thanks @jtackaberry
### Implementation changes and bug fixes
- [PR #1567](https://github.com/rqlite/rqlite/pull/1567): Refactor to make more use of `progress` module.
- [Commit d1cc802](https://github.com/rqlite/rqlite/commit/d1cc80229221ff51cd4741cc7a2e05e87f0337cb): Fix return codes in `HasData()`.
## 8.15.0 (January 4th 2024)

@ -10,6 +10,7 @@ import (
"sync"
"github.com/rqlite/rqlite/v8/command/proto"
"github.com/rqlite/rqlite/v8/progress"
)
const (
@ -37,7 +38,7 @@ var gzipWriterPool = sync.Pool{
// Chunker is a reader that reads from an underlying io.Reader and returns
// LoadChunkRequests of a given size.
type Chunker struct {
r *CountingReader
r *progress.CountingReader
chunkSize int64
streamID string
@ -52,7 +53,7 @@ type Chunker struct {
// LoadChunkRequests of size chunkSize.
func NewChunker(r io.Reader, chunkSize int64) *Chunker {
return &Chunker{
r: NewCountingReader(r),
r: progress.NewCountingReader(r),
chunkSize: chunkSize,
streamID: generateStreamID(),
}

@ -1,57 +0,0 @@
package chunking
import (
"io"
)
// CountingReader is a wrapper around an io.Reader that counts the number of
// bytes read.
type CountingReader struct {
r io.Reader
n int64
}
// Read reads from the underlying io.Reader.
func (cr *CountingReader) Read(p []byte) (int, error) {
n, err := cr.r.Read(p)
cr.n += int64(n)
return n, err
}
// Count returns the number of bytes read.
func (cr *CountingReader) Count() int64 {
return cr.n
}
// NewCountingReader returns a new CountingReader that reads from r.
func NewCountingReader(r io.Reader) *CountingReader {
return &CountingReader{
r: r,
}
}
// CountingWriter is a wrapper around an io.Writer that counts the number of
// bytes written.
type CountingWriter struct {
w io.Writer
n int64
}
// Write writes to the underlying io.Writer.
func (cw *CountingWriter) Write(p []byte) (int, error) {
n, err := cw.w.Write(p)
cw.n += int64(n)
return n, err
}
// Count returns the number of bytes written.
func (cw *CountingWriter) Count() int64 {
return cw.n
}
// NewCountingWriter returns a new CountingWriter that writes to w.
func NewCountingWriter(w io.Writer) *CountingWriter {
return &CountingWriter{
w: w,
}
}

@ -3,12 +3,14 @@ package gzip
import (
"compress/gzip"
"io"
"github.com/rqlite/rqlite/v8/progress"
)
// Decompressor is a wrapper around a gzip.Reader that reads from an io.Reader
// and decompresses the data.
type Decompressor struct {
cr *CountingReader
cr *progress.CountingReader
gzr *gzip.Reader
nRx int64
@ -19,7 +21,7 @@ type Decompressor struct {
// decompresses the data using gzip.
func NewDecompressor(r io.Reader) *Decompressor {
return &Decompressor{
cr: NewCountingReader(r),
cr: progress.NewCountingReader(r),
}
}
@ -56,24 +58,3 @@ func (c *Decompressor) Read(p []byte) (nn int, err error) {
}
return n, err
}
// CountingReader is a wrapper around io.Reader that counts the number of bytes
// read.
type CountingReader struct {
r io.Reader
n int64
}
// NewCountingReader returns an instantiated CountingReader that reads from r.
func NewCountingReader(r io.Reader) *CountingReader {
return &CountingReader{
r: r,
}
}
// Read reads data.
func (c *CountingReader) Read(p []byte) (n int, err error) {
n, err = c.r.Read(p)
c.n += int64(n)
return n, err
}

Loading…
Cancel
Save