Copyright 2016 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package gensupport

import (
	
	

	
)
MediaBuffer buffers data from an io.Reader to support uploading media in retryable chunks. It should be created with NewMediaBuffer.
type MediaBuffer struct {
	media io.Reader

	chunk []byte // The current chunk which is pending upload.  The capacity is the chunk size.
	err   error  // Any error generated when populating chunk by reading media.
The absolute position of chunk in the underlying media.
NewMediaBuffer initializes a MediaBuffer.
func ( io.Reader,  int) *MediaBuffer {
	return &MediaBuffer{media: , chunk: make([]byte, 0, )}
}
Chunk returns the current buffered chunk, the offset in the underlying media from which the chunk is drawn, and the size of the chunk. Successive calls to Chunk return the same chunk between calls to Next.
There may already be data in chunk if Next has not been called since the previous call to Chunk.
	if .err == nil && len(.chunk) == 0 {
		.err = .loadChunk()
	}
	return bytes.NewReader(.chunk), .off, len(.chunk), .err
}
loadChunk will read from media into chunk, up to the capacity of chunk.
func ( *MediaBuffer) () error {
	 := cap(.chunk)
	.chunk = .chunk[:]

	 := 0
	var  error
	for  == nil &&  <  {
		var  int
		,  = .media.Read(.chunk[:])
		 += 
	}
	.chunk = .chunk[:]
	return 
}
Next advances to the next chunk, which will be returned by the next call to Chunk. Calls to Next without a corresponding prior call to Chunk will have no effect.
func ( *MediaBuffer) () {
	.off += int64(len(.chunk))
	.chunk = .chunk[0:0]
}

type readerTyper struct {
	io.Reader
	googleapi.ContentTyper
}
ReaderAtToReader adapts a ReaderAt to be used as a Reader. If ra implements googleapi.ContentTyper, then the returned reader will also implement googleapi.ContentTyper, delegating to ra.
func ( io.ReaderAt,  int64) io.Reader {
	 := io.NewSectionReader(, 0, )
	if ,  := .(googleapi.ContentTyper);  {
		return readerTyper{, }
	}
	return