Skip to content

Instantly share code, notes, and snippets.

@mattn
Last active December 21, 2015 15:48
Show Gist options
  • Save mattn/6328663 to your computer and use it in GitHub Desktop.
Save mattn/6328663 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"fmt"
"io"
)
type BytesReadCloser struct {
*bytes.Reader
}
func NewBytesReadCloser(b []byte) io.ReadCloser {
return BytesReadCloser{bytes.NewReader(b)}
}
func (brc BytesReadCloser) Close() error {
return nil
}
func testReadCloser(rc io.ReadCloser) {
var b[5] byte
rc.Read(b[:])
rc.Close()
fmt.Println(string(b[:]))
}
func main() {
brc := NewBytesReadCloser([]byte("hello world"))
testReadCloser(brc)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment