Documentation
¶
Overview ¶
Package copycat provides unidirectional and bidirectional copy functions.
Example ¶
package main import ( "bytes" "fmt" "io" "strings" "github.com/humuzhu/copycat" ) func main() { // undirection copy src := strings.NewReader("copycat") dst := &bytes.Buffer{} err := copycat.Undi(dst, src) if err != nil { fmt.Println(err) } else { fmt.Println(dst.String()) } // bidirectional copy local := &ExampleReadWriter{Reader: strings.NewReader("copy"), Writer: &bytes.Buffer{}} remote := &ExampleReadWriter{Reader: strings.NewReader("bidi"), Writer: &bytes.Buffer{}} err = copycat.Bidi(local, remote) if err != nil { fmt.Println(err) } else { fmt.Println("copycat", local.Writer.String(), remote.Writer.String()) } } type ExampleReadWriter struct { Reader io.Reader Writer *bytes.Buffer } func (rw *ExampleReadWriter) Read(p []byte) (n int, err error) { return rw.Reader.Read(p) } func (rw *ExampleReadWriter) Write(p []byte) (n int, err error) { return rw.Writer.Write(p) }
Output: copycat copycat bidi copy
Index ¶
Examples ¶
Constants ¶
View Source
const (
// DefaultBlockSize is the default block size used in copy working.
DefaultBlockSize = 32 * 1024
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(opt *copyOption)
Option represents setting of works.
func WithBlockSize ¶
WithBlockSize sets the block size used in copy works.
func WithContext ¶
WithContext sets the context used in copy works. If context canceled, copy function returns with error.
Click to show internal directories.
Click to hide internal directories.