lbcwallet/txstore/fixedIO_test.go
Josh Rickmar f36a83b3cc Rename tx package to txstore.
Prodded by @davecgh, and I had this change in the back of my head for
a while now anyways.
2014-05-08 14:51:33 -05:00

41 lines
790 B
Go

// copied from btcwire
// Copyright (c) 2013-2014 Conformal Systems LLC.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package txstore_test
import (
"io"
)
// fixedWriter implements the io.Writer interface and intentially allows
// testing of error paths by forcing short writes.
type fixedWriter struct {
b []byte
pos int
}
// Write ...
func (w *fixedWriter) Write(p []byte) (n int, err error) {
lenp := len(p)
if w.pos+lenp > cap(w.b) {
return 0, io.ErrShortWrite
}
n = lenp
w.pos += copy(w.b[w.pos:], p)
return
}
// Bytes ...
func (w *fixedWriter) Bytes() []byte {
return w.b
}
// newFixedWriter...
func newFixedWriter(max int64) *fixedWriter {
b := make([]byte, max, max)
fw := fixedWriter{b, 0}
return &fw
}