Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
// StoreHost is a gs endpoint (s3 compatible api)
StoreHost = "storage.googleapis.com"
)
Functions ¶
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader will read in streamed bytes from the gs object.NewgsClient
func NewReader ¶
Example ¶
pth := fmt.Sprintf("gs://%v/read/test.txt", testBucket) r, err := NewReader(pth, testAccessKey, testSecretKey) fmt.Println(err) // output: <nil> if r == nil { return } fmt.Println(r.sts.Path) // output: gs://task-tools-gstest/read/test.txt fmt.Println(r.sts.Size) // output: 20
Output: <nil> gs://task-tools-gstest/read/test.txt 20
func (*Reader) Close ¶
Example ¶
pth := fmt.Sprintf("gs://%v/read/test.txt", testBucket) r, _ := NewReader(pth, testAccessKey, testSecretKey) 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("gs://%v/read/test.txt", testBucket) r, err := NewReader(pth, testAccessKey, testSecretKey) 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("gs://%v/read/test.txt", testBucket) r, _ := NewReader(pth, testAccessKey, testSecretKey) 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 gs destination after calling Close(). Close() must be called in order for the written contents to be written to gs.
Calling Abort() before Close() will cleanup the buffer. Calling Close() after Abort() will not result in any writing to gs.
Calling Abort() after Close() will do nothing.
func NewWriter ¶
Example ¶
pth := fmt.Sprintf("gs://%v/write/test.txt", testBucket) w, err := NewWriter(pth, testAccessKey, testSecretKey, nil) if w == nil { return } fmt.Println(err) // output: <nil> fmt.Println(w.sts.Path) // output: gs://task-tools-gstest/write/test.txt fmt.Println(w.gsClient != nil) // output: true fmt.Println(w.bfr != nil) // output: true fmt.Println(w.bucket) // output: task-tools-gstest fmt.Println(w.objPth) // output: write/test.txt fmt.Println(w.tmpPth == "") // output: true
Output: <nil> gs://task-tools-gstest/write/test.txt true true task-tools-gstest 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("gs://%v/write/test.txt", testBucket) w, _ := NewWriter(pth, testAccessKey, testSecretKey, 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 gs object writing failed.
Calling Abort after Close will do nothing. Writing after calling Close has undefined behavior.
Example ¶
pth := fmt.Sprintf("gs://%v/write/test.txt", testBucket) w, _ := NewWriter(pth, testAccessKey, testSecretKey, 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("gs://%v/write/test.txt", testBucket) w, _ := NewWriter(pth, testAccessKey, testSecretKey, nil) if w == nil { return } w.WriteLine([]byte("test line")) w.WriteLine([]byte("test line")) sts := w.Stats() fmt.Println(sts.Path) // output: gs://task-tools-gstest/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: gs://task-tools-gstest/write/test.txt 20 2 0 true
func (*Writer) Write ¶
Example ¶
pth := fmt.Sprintf("gs://%v/write/test.txt", testBucket) w, _ := NewWriter(pth, testAccessKey, testSecretKey, nil) if w == nil { return } n, err := w.Write([]byte("test line")) fmt.Println(n) // output: 9 fmt.Println(err) // output: <nil>
Output: 9 <nil>