limitopen

package
v0.9.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2021 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package limitopen provides an alternative to os.Open, to limit the size of the file read into memory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(path string) (r io.ReadCloser, size int64, err error)

Open opens a path for read.

It's similar to os.Open, but with the following differences:

1. It returns io.ReadCloser other than *os.File,

2. It returns the size reported by the system to the user.

3. The io.ReadCloser returned would be guaranteed to be not able to read beyond the size returned (for example, if you use this function to open /dev/zero, the system would return 0 as the size, and as a result when reading from r you would get EOF immediately, instead of being able to read from it indefinitely)

It would never return both non-nil r and err. When err is nil it's the caller's responsibility to close r returned.

func OpenWithLimit

func OpenWithLimit(path string, softLimit, hardLimit int64) (io.ReadCloser, error)

OpenWithLimit calls Open with limit checks.

It always reports the size of the path as a runtime gauge (with "limitopen.size" as the metrics path and path label). When softLimit > 0 and the size of the path as reported by the os is larger, it will also use log.ErrorWithSentry to report it. When hardLimit > 0 and the size of the path as reported by the os is larger, it will close the file and return an error directly.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL