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

Method Read

pkg/signer/request-signature-streaming.go:431–491  ·  view source on GitHub ↗

Read - this method performs chunk upload signature providing a io.Reader interface.

(buf []byte)

Source from the content-addressed store, hash-verified

429// Read - this method performs chunk upload signature providing a
430// io.Reader interface.
431func (s *StreamingReader) Read(buf []byte) (int, error) {
432 switch {
433 // After the last chunk is read from underlying reader, we
434 // never re-fill s.buf.
435 case s.done:
436
437 // s.buf will be (re-)filled with next chunk when has lesser
438 // bytes than asked for.
439 case s.buf.Len() < len(buf):
440 s.chunkBufLen = 0
441 for {
442 n1, err := s.baseReadCloser.Read(s.chunkBuf[s.chunkBufLen:])
443 // Usually we validate `err` first, but in this case
444 // we are validating n > 0 for the following reasons.
445 //
446 // 1. n > 0, err is one of io.EOF, nil (near end of stream)
447 // A Reader returning a non-zero number of bytes at the end
448 // of the input stream may return either err == EOF or err == nil
449 //
450 // 2. n == 0, err is io.EOF (actual end of stream)
451 //
452 // Callers should always process the n > 0 bytes returned
453 // before considering the error err.
454 if n1 > 0 {
455 s.chunkBufLen += n1
456 s.bytesRead += int64(n1)
457
458 if s.chunkBufLen == payloadChunkSize ||
459 (s.chunkNum == s.totalChunks-1 &&
460 s.chunkBufLen == s.lastChunkSize) {
461 // Sign the chunk and write it to s.buf.
462 s.signChunk(s.chunkBufLen, true)
463 break
464 }
465 }
466 if err != nil {
467 if err == io.EOF {
468 // No more data left in baseReader - last chunk.
469 // Done reading the last chunk from baseReader.
470 s.done = true
471
472 // bytes read from baseReader different than
473 // content length provided.
474 if s.bytesRead != s.contentLen {
475 return 0, fmt.Errorf("http: ContentLength=%d with Body length %d", s.contentLen, s.bytesRead)
476 }
477
478 // Sign the chunk and write it to s.buf.
479 s.signChunk(0, len(s.trailer) == 0)
480 if len(s.trailer) > 0 {
481 // Trailer must be set now.
482 s.addSignedTrailer(s.trailer)
483 }
484 break
485 }
486 return 0, err
487 }
488 }

Callers

nothing calls this directly

Calls 3

signChunkMethod · 0.95
addSignedTrailerMethod · 0.95
LenMethod · 0.80

Tested by

no test coverage detected