multipartkit

package
v0.0.0-...-cdb57bf Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

This file is subject to the terms and conditions defined in file 'LICENSE.txt', which is part of this source code package.

This file is subject to the terms and conditions defined in file 'LICENSE.txt', which is part of this source code package.

Index

Constants

View Source
const DefaultBufferSize = 5 * 1024 * 1024 // 5 MB

DefaultBufferSize defines a default buffer size (5 MB) for writing parts.

Variables

This section is empty.

Functions

func ComputeHash

func ComputeHash(reader io.Reader, bufferSize int) (string, error)

ComputeHash streams data from the provided `io.Reader` and calculates the SHA-256 hash. The hash is returned as UrlSafe base64 encoded string.

Types

type MultipartBuilder

type MultipartBuilder struct {
	// contains filtered or unexported fields
}

MultipartBuilder is responsible for building multipart data with writers and buffer size.

func NewMultipartBuilder

func NewMultipartBuilder(w io.Writer, bufferSize int) (*MultipartBuilder, error)

NewMultipartBuilder initializes a new MultipartBuilder using an io.Writer and buffer size.

func (*MultipartBuilder) AddBytes

func (mb *MultipartBuilder) AddBytes(partName, fileName, contentType string, data []byte) error

AddBytes writes a file (provided as bytes) into the multipart builder with the given filename and MIME type.

func (*MultipartBuilder) AddFile

func (mb *MultipartBuilder) AddFile(partName, filePath, contentType string) error

AddFile writes the content of a file as a part of the multipart stream with Content-Size and Content-Hash headers.

func (*MultipartBuilder) AddProtobuf

func (mb *MultipartBuilder) AddProtobuf(partName string, pb interface{}) error

AddProtobuf writes a single or slice of Protobuf messages as a part of the multipart stream, including Content-Size and Content-Hash headers.

func (*MultipartBuilder) Finalize

func (mb *MultipartBuilder) Finalize() error

Finalize writes the ending boundary and closes the multipart writer.

func (*MultipartBuilder) GetBoundary

func (mb *MultipartBuilder) GetBoundary() string

Boundary retrieves the boundary used by the multipart writer.

type MultipartReader

type MultipartReader struct {
	// contains filtered or unexported fields
}

MultipartReader reads multipart data from a stream and supports configurable buffer size.

func NewMultipartReader

func NewMultipartReader(r io.Reader, boundary string, bufferSize int) (*MultipartReader, error)

NewMultipartReader creates a new instance of MultipartReader.

func (*MultipartReader) MetadataJSON

func (mr *MultipartReader) MetadataJSON(w io.Writer) error

MetadataJSON streams the JSON representation of the metadata for all parts in the multipart message.

func (*MultipartReader) NextPart

func (mr *MultipartReader) NextPart() (*multipart.Part, error)

NextPart returns the next part of the multipart stream using the current reader.

type PartMetadata

type PartMetadata struct {
	PartName string                 `json:"part_name"`
	PartType string                 `json:"part_type"`
	Headers  map[string]interface{} `json:"headers"`
}

PartMetadata describes metadata for each part of the multipart message.

Jump to

Keyboard shortcuts

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