interceptors

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Gzip = &lino_s3.Interceptor{
	PostGet: func(output *s3.GetObjectOutput) (*s3.GetObjectOutput, error) {
		gr, err := gzip.NewReader(output.Body)
		if err != nil {
			return nil, err
		}

		output.Body = gr
		return output, nil
	},
	PrePut: func(input *s3.PutObjectInput) (*s3.PutObjectInput, error) {
		var buf bytes.Buffer
		gz := gzip.NewWriter(&buf)

		data, err := io.ReadAll(input.Body)
		if err != nil {
			return nil, err
		}

		if _, err := gz.Write(data); err != nil {
			return nil, err
		}

		if err := gz.Close(); err != nil {
			return nil, err
		}

		input.Body = bytes.NewReader(buf.Bytes())
		return input, nil
	},
	PreUpload: func(input *s3manager.UploadInput) (*s3manager.UploadInput, error) {
		pr, pw := io.Pipe()
		go func() {
			gw := gzip.NewWriter(pw)

			if _, err := io.Copy(gw, input.Body); err != nil {
				pw.CloseWithError(err)
				return
			}

			if err := gw.Close(); err != nil {
				pw.CloseWithError(err)
				return
			}

			pw.Close()
		}()

		input.Body = pr
		return input, nil
	},
}
View Source
var Zstd = &lino_s3.Interceptor{
	PostGet: func(output *s3.GetObjectOutput) (*s3.GetObjectOutput, error) {
		zr, err := zstd.NewReader(output.Body)
		if err != nil {
			return nil, err
		}

		output.Body = zr.IOReadCloser()
		return output, nil
	},
	PrePut: func(input *s3.PutObjectInput) (*s3.PutObjectInput, error) {
		var buf bytes.Buffer
		zz, err := zstd.NewWriter(&buf)
		if err != nil {
			return nil, err
		}

		data, err := io.ReadAll(input.Body)
		if err != nil {
			return nil, err
		}

		if _, err := zz.Write(data); err != nil {
			return nil, err
		}

		if err := zz.Close(); err != nil {
			return nil, err
		}

		input.Body = bytes.NewReader(buf.Bytes())
		return input, nil
	},
	PreUpload: func(input *s3manager.UploadInput) (*s3manager.UploadInput, error) {
		pr, pw := io.Pipe()
		go func() {
			zw, err := zstd.NewWriter(pw)
			if err != nil {
				pw.CloseWithError(err)
				return
			}

			if _, err := io.Copy(zw, input.Body); err != nil {
				pw.CloseWithError(err)
				return
			}

			if err := zw.Close(); err != nil {
				pw.CloseWithError(err)
				return
			}

			pw.Close()
		}()

		input.Body = pr
		return input, nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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