mirror of
https://github.com/pgsty/minio.git
synced 2026-07-21 05:00:22 +03:00
tests: Unit tests and fixes for copyBuffer. (#2333)
- Unit tests for copyBuffer. - Shadowing fix for copyBuffer.
This commit is contained in:
committed by
Harshavardhana
parent
8d090a20ce
commit
9baf599c91
@@ -400,6 +400,36 @@ func getRandomBucketName() string {
|
||||
|
||||
}
|
||||
|
||||
// TruncateWriter - Writes `n` bytes, then returns with number of bytes written.
|
||||
// differs from iotest.TruncateWriter, the difference is commented in the Write method.
|
||||
func TruncateWriter(w io.Writer, n int64) io.Writer {
|
||||
return &truncateWriter{w, n}
|
||||
}
|
||||
|
||||
type truncateWriter struct {
|
||||
w io.Writer
|
||||
n int64
|
||||
}
|
||||
|
||||
func (t *truncateWriter) Write(p []byte) (n int, err error) {
|
||||
if t.n <= 0 {
|
||||
return len(p), nil
|
||||
}
|
||||
// real write
|
||||
n = len(p)
|
||||
if int64(n) > t.n {
|
||||
n = int(t.n)
|
||||
}
|
||||
n, err = t.w.Write(p[0:n])
|
||||
t.n -= int64(n)
|
||||
// Removed from iotest.TruncateWriter.
|
||||
// Need the Write method to return truncated number of bytes written, not the size of the buffer requested to be written.
|
||||
// if err == nil {
|
||||
// n = len(p)
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
||||
// NewEOFWriter returns a Writer that writes to w,
|
||||
// but returns EOF error after writing n bytes.
|
||||
func NewEOFWriter(w io.Writer, n int64) io.Writer {
|
||||
|
||||
Reference in New Issue
Block a user