https://github.com/ipfs/go-ipfs
Raw File
Tip revision: a8b56d3ad7789ca2ec12257a00d8d0408c3c0c9e authored by Jeromy on 25 March 2017, 03:34:49 UTC
Ipfs 0.4.8-rc1
Tip revision: a8b56d3
writerat.go
package ipns

import "io"

type WriteAtBuf interface {
	io.WriterAt
	Bytes() []byte
}

type writerAt struct {
	buf []byte
}

func NewWriterAtFromBytes(b []byte) WriteAtBuf {
	return &writerAt{b}
}

// TODO: make this better in the future, this is just a quick hack for now
func (wa *writerAt) WriteAt(p []byte, off int64) (int, error) {
	if off+int64(len(p)) > int64(len(wa.buf)) {
		wa.buf = append(wa.buf, make([]byte, (int(off)+len(p))-len(wa.buf))...)
	}
	copy(wa.buf[off:], p)
	return len(p), nil
}

func (wa *writerAt) Bytes() []byte {
	return wa.buf
}
back to top