MCPcopy
hub / github.com/minio/minio-go / Read

Method Read

api-get-object.go:377–428  ·  view source on GitHub ↗

Read reads up to len(b) bytes into b. It returns the number of bytes read (0 <= n <= len(b)) and any error encountered. Returns io.EOF upon end of file.

(b []byte)

Source from the content-addressed store, hash-verified

375// bytes read (0 <= n <= len(b)) and any error encountered. Returns
376// io.EOF upon end of file.
377func (o *Object) Read(b []byte) (n int, err error) {
378 if o == nil {
379 return 0, errInvalidArgument("Object is nil")
380 }
381
382 // Locking.
383 o.mutex.Lock()
384 defer o.mutex.Unlock()
385
386 // prevErr is previous error saved from previous operation.
387 if o.prevErr != nil || o.isClosed {
388 return 0, o.prevErr
389 }
390
391 // Create a new request.
392 readReq := getRequest{
393 isReadOp: true,
394 beenRead: o.beenRead,
395 Buffer: b,
396 }
397
398 // Alert that this is the first request.
399 if !o.isStarted {
400 readReq.isFirstReq = true
401 }
402
403 // Ask to establish a new data fetch routine based on seekData flag
404 readReq.DidOffsetChange = o.seekData
405 readReq.Offset = o.currOffset
406
407 // Send and receive from the first request.
408 response, err := o.doGetRequest(readReq)
409 if err != nil && err != io.EOF {
410 // Save the error for future calls.
411 o.prevErr = err
412 return response.Size, err
413 }
414
415 // Bytes read.
416 bytesRead := int64(response.Size)
417
418 // Set the new offset.
419 oerr := o.setOffset(bytesRead)
420 if oerr != nil {
421 // Save the error for future calls.
422 o.prevErr = oerr
423 return response.Size, oerr
424 }
425
426 // Return the response.
427 return response.Size, err
428}
429
430// Stat returns the ObjectInfo structure describing Object.
431func (o *Object) Stat() (ObjectInfo, error) {

Callers 5

TestFullObjectChecksum64Function · 0.45
TestCoreMultipartUploadFunction · 0.45
testGetObjectS3ZipFunction · 0.45

Calls 3

doGetRequestMethod · 0.95
setOffsetMethod · 0.95
errInvalidArgumentFunction · 0.85

Tested by 2

TestFullObjectChecksum64Function · 0.36
TestCoreMultipartUploadFunction · 0.36