Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // domain of s3 compatible api S3Host = "s3.amazonaws.com" GSHost = "storage.googleapis.com" )
Functions ¶
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader will read in streamed bytes from the s3 object.NewS3Client
func NewReader ¶
Example ¶
pth := fmt.Sprintf("mcs://%v/read/test.txt", testBucket) r, err := NewReader(pth, testOption) if r == nil { return } fmt.Println(err) // output: <nil> fmt.Println(r.sts.Path) // output: mcs://task-tools-test/read/test.txt fmt.Println(r.sts.Size) // output: 20
Output: <nil> mcs://task-tools-test/read/test.txt 20
func (*Reader) Close ¶
Example ¶
pth := fmt.Sprintf("mcs://%v/read/test.txt", testBucket) r, _ := NewReader(pth, testOption) if r == nil { return } r.ReadLine() r.ReadLine() r.ReadLine() err := r.Close() sts := r.Stats() fmt.Println(err) // output: <nil> fmt.Println(sts.ByteCnt) // output: 20 fmt.Println(sts.LineCnt) // output: 2 fmt.Println(sts.Checksum) // output: 54f30d75cf7374c7e524a4530dbc93c2
Output: <nil> 20 2 54f30d75cf7374c7e524a4530dbc93c2
func (*Reader) Read ¶
Example ¶
pth := fmt.Sprintf("mcs://%v/read/test.txt", testBucket) r, err := NewReader(pth, testOption) if r == nil { return } b := make([]byte, 20) n, err := r.Read(b) fmt.Println(n) // output: 20 fmt.Println(err) // output: <nil> fmt.Print(string(b)) // output: test line, test line fmt.Println(r.sts.ByteCnt) // output: 20 fmt.Println(r.sts.LineCnt) // output: 0
Output: 20 <nil> test line test line 20 0
func (*Reader) ReadLine ¶
Example ¶
pth := fmt.Sprintf("mcs://%v/read/test.txt", testBucket) r, _ := NewReader(pth, testOption) if r == nil { return } ln1, err1 := r.ReadLine() ln2, err2 := r.ReadLine() fmt.Println(string(ln1)) // output: test line fmt.Println(err1) // output: <nil> fmt.Println(string(ln2)) // output: test line fmt.Println(err2) // output: <nil> fmt.Println(r.sts.ByteCnt) // output: 20 fmt.Println(r.sts.LineCnt) // output: 2
Output: test line <nil> test line <nil> 20 2
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer will write to local buffer first and will copy all the written contents to the S3 destination after calling Close(). Close() must be called in order for the written contents to be written to S3.
Calling Abort() before Close() will cleanup the buffer. Calling Close() after Abort() will not result in any writing to S3.
Calling Abort() after Close() will do nothing.
func NewWriter ¶
Example ¶
pth := fmt.Sprintf("mcs://%v/write/test.txt", testBucket) w, err := NewWriter(pth, testOption, nil) if w == nil { return } fmt.Println(err) // output: <nil> fmt.Println(w.sts.Path) // output: mcs://task-tools-test/write/test.txt fmt.Println(w.client != nil) // output: true fmt.Println(w.bfr != nil) // output: true fmt.Println(w.bucket) // output: task-tools-test fmt.Println(w.objPth) // output: write/test.txt fmt.Println(w.tmpPth == "") // output: true
Output: <nil> mcs://task-tools-test/write/test.txt true true task-tools-test write/test.txt true
func (*Writer) Abort ¶
Abort will: - clear and close buffer
Calling Close after Abort will do nothing. Writing after calling Abort has undefined behavior.
Example ¶
pth := fmt.Sprintf("mcs://%v/write/test.txt", testBucket) w, _ := NewWriter(pth, testOption, nil) if w == nil { return } w.WriteLine([]byte("test line")) fmt.Println(w.done) // output: false err := w.Abort() fmt.Println(err) // output: <nil> fmt.Println(w.done) // output: true
Output: false <nil> true
func (*Writer) Close ¶
Close will: - calculate final checksum - copy (mv) buffer to pth file - clear and close buffer - report any errors
If an error is returned it should be assumed that S3 object writing failed.
Calling Abort after Close will do nothing. Writing after calling Close has undefined behavior.
Example ¶
pth := fmt.Sprintf("mcs://%v/write/test.txt", testBucket) w, _ := NewWriter(pth, testOption, nil) if w == nil { return } w.WriteLine([]byte("test line")) w.WriteLine([]byte("test line")) err := w.Close() fmt.Println(err) // output: <nil> fmt.Println(w.done) // output: true fmt.Println(w.objSts.Checksum != "") // output: true // cleanup rmTestFile(pth)
Output: <nil> true true
func (*Writer) Stats ¶
Example ¶
pth := fmt.Sprintf("mcs://%v/write/test.txt", testBucket) w, _ := NewWriter(pth, testOption, nil) if w == nil { return } w.WriteLine([]byte("test line")) w.WriteLine([]byte("test line")) sts := w.Stats() fmt.Println(sts.Path) // output: mcs://task-tools-test/write/test.txt fmt.Println(sts.ByteCnt) // output: 20 fmt.Println(sts.LineCnt) // output: 2 fmt.Println(sts.Size) // output: 0 fmt.Println(sts.Checksum) // output: fmt.Println(sts.Created == "") // output: true
Output: mcs://task-tools-test/write/test.txt 20 2 0 true