Documentation
¶
Index ¶
- Constants
- Variables
- func CloseAndRemove(f *os.File) error
- func FilesEqual(fileA, fileB string) (bool, error)
- func NewHTTPClient(userAgent, version string) *http.Client
- func ReplaceFile(data io.Reader, dest string) error
- func ReplaceFileIfDifferent(data io.Reader, dest string) (bool, error)
- type BufferedReader
- type DefaultHeaderTransport
Constants ¶
const DefaultReadBufferSize = 4 * 1024
DefaultReadBufferSize is the buffer size used for the DefaultBufferedReader .
const DefaultTimeout = 10 * time.Second
Variables ¶
var DefaultBufferedReader = NewBufferedReader(DefaultReadBufferSize)
DefaultBufferedReader is a BufferedReader initialized with buffers of the DefaultReadBufferSize .
Functions ¶
func CloseAndRemove ¶
CloseAndRemove first closes the given file and secondly deletes it.
func FilesEqual ¶
FilesEqual returns true if both files are equal, i.e. if both store the same bytes.
func NewHTTPClient ¶
NewHTTPClient returns an HTTP client initialized with a DefaultHeaderTransport and with DefaultTimeout.
func ReplaceFile ¶
ReplaceFile overwrites a file atomically by first creating a temporary file with the given data and afterwards replacing the destination with temporary file. File permissions of the destination are kept. The destination is unchanged if an intermediate error occurs.
func ReplaceFileIfDifferent ¶
ReplaceFileIfDifferent acts like ReplaceFile but first checks if the content of dest and data are different. Note that this requires to buffer the data Reader in memory, unlike ReplaceFile. If dest was replaced the boolean return value is true and otherwise false.
Types ¶
type BufferedReader ¶
type BufferedReader struct {
// contains filtered or unexported fields
}
BufferedReader implements equality checks for io.Reader .
func NewBufferedReader ¶
func NewBufferedReader(bufSize int64) *BufferedReader
NewBufferedReader returns a BufferedReader initialized with the given buffers of the given size. Usually there is no need to instantiate it yourself, use the DefaultBufferedReader instead.
func (*BufferedReader) ReaderEqual ¶
func (br *BufferedReader) ReaderEqual(a, b io.Reader) (bool, error)
ReaderEqual returns true if both readers returned the same bytes.
type DefaultHeaderTransport ¶
type DefaultHeaderTransport struct {
// contains filtered or unexported fields
}
DefaultHeaderTransport is an http.Transport that inserts user-agent and x-client-version headers.
func NewDefaultHeaderTransport ¶
func NewDefaultHeaderTransport(userAgent, version string) *DefaultHeaderTransport
NewDefaultHeaderTransport returns an initialied DefaultHeaderTransport that uses the http.DefaultTransport .
func (*DefaultHeaderTransport) SetBaseTransport ¶
func (dht *DefaultHeaderTransport) SetBaseTransport(baseTransport http.RoundTripper)
SetBaseTransport allows to replace the base transport.