compressor

package
v0.0.0-...-cb73b9c Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package compressor provides a simple interface used for a post-rotate Rotatorr hook that compresses files.

Index

Constants

View Source
const SuffixGZ = ".gz"

SuffixGZ is appended to a fileName to make the new compressed file name.

Variables

View Source
var CompressLevel = gzip.DefaultCompression //nolint:gochecknoglobals

CompressLevel sets the global compression level.

View Source
var Filer = filer.Default() //nolint:gochecknoglobals

Filer allows overriding os-file procedures.

Functions

func CompressBackground

func CompressBackground(fileName string, cb func(report *Report))

CompressBackground runs a file compression in the background. A report is sent to a provided callback function when compression finishes. Avoid using this on files that may be renamed by another thread.

func CompressBackgroundPostRotate

func CompressBackgroundPostRotate(_, fileName string)

CompressBackgroundPostRotate satisfies the post-rotate interface in rotatorr. This rotates a file and writes the success to the old log file, or the error to the existing log file (using the global logger). This is safe for use with the timerotator package.

func CompressBackgroundWithLog

func CompressBackgroundWithLog(fileName string, printf func(msg string, fmt ...interface{}))

CompressBackgroundWithLog like CompressBackground runs a file compression in the background, but writes a log message when finished instead of a callback. Avoid using this on files that may be renamed by another thread.

func CompressPostRotate

func CompressPostRotate(_, fileName string)

CompressPostRotate satisfies the post-rotate interface in rotatorr. This rotates a file and writes the success to the old log file, or the error to the existing log file (using the global logger). This is safe for use with the introtator package.

func CompressWithLog

func CompressWithLog(fileName string, printf func(msg string, fmt ...interface{}))

CompressWithLog is the same as Compress, except it writes a report log instead of returning it.

func Log

func Log(report *Report, printf func(msg string, fmt ...interface{}))

Log sends a report to a custom procedure.

Types

type Report

type Report struct {
	OldFile string
	NewFile string
	OldSize int64
	NewSize int64
	Elapsed time.Duration
	Error   error
}

Report contains a report of the compression operation. Always check for Error to make sure the New* data is valid.

func Compress

func Compress(fileName string) (*Report, error)

Compress gzips a file and returns a report. Blocks until finished.

Jump to

Keyboard shortcuts

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