iox

package
v0.0.0-...-d0ebcda Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: BSD-3-Clause Imports: 12 Imported by: 1

Documentation

Index

Examples

Constants

View Source
const (
	AcceptEncoding      = "Accept-Encoding"
	AcceptEncodingValue = "gzip, deflate, br"
	ContentEncoding     = "Content-Encoding"

	GzipEncoding     = "gzip"
	BrotliEncoding   = "br"
	DeflateEncoding  = "deflate"
	CompressEncoding = "compress"
	NoneEncoding     = "none"

	ApplicationGzip    = "application/x-gzip"
	ApplicationBrotli  = "application/x-br"
	ApplicationDeflate = "application/x-deflate"
)
View Source
const (
	CwdVariable = "[cwd]"
)
View Source
const (
	PkgPath = "github/behavioral-ai/core/iox"
)

Variables

This section is empty.

Functions

func Decode

func Decode(buf []byte, h http.Header) ([]byte, *core.Status)

Decode - decode a []byte

func FileName

func FileName(uri any) string

FileName - return the OS correct file name from a URI

func Mount

func Mount(fs embed.FS)

func ReadAll

func ReadAll(body io.Reader, h http.Header) ([]byte, *core.Status)

ReadAll - read the body with a Status

func ReadFile

func ReadFile(uri any) ([]byte, *core.Status)

ReadFile - read a file with a Status

Example
s := status504
buf, status := ReadFile(s)
fmt.Printf("test: ReadFile(%v) -> [type:%v] [buf:%v] [status:%v]\n", s, reflect.TypeOf(s), len(buf), status)

s = address1Url
buf, status = ReadFile(s)
fmt.Printf("test: ReadFile(%v) -> [type:%v] [buf:%v] [status:%v]\n", s, reflect.TypeOf(s), len(buf), status)

s = status504
u := parseRaw(s)
buf, status = ReadFile(u.String())
fmt.Printf("test: ReadFile(%v) -> [type:%v] [buf:%v] [status:%v]\n", s, reflect.TypeOf(u), len(buf), status)

s = address1Url
u = parseRaw(s)
buf, status = ReadFile(u.String())
fmt.Printf("test: ReadFile(%v) -> [type:%v] [buf:%v] [status:%v]\n", s, reflect.TypeOf(u), len(buf), status)
Output:

test: ReadFile(file://[cwd]/test/status-504.json) -> [type:string] [buf:82] [status:OK]
test: ReadFile(file://[cwd]/test/address1.json) -> [type:string] [buf:68] [status:OK]
test: ReadFile(file://[cwd]/test/status-504.json) -> [type:*url.URL] [buf:82] [status:OK]
test: ReadFile(file://[cwd]/test/address1.json) -> [type:*url.URL] [buf:68] [status:OK]

func ReadFileWithEncoding

func ReadFileWithEncoding(uri string, h http.Header) ([]byte, *core.Status)

ReadFileWithEncoding - read a file with a possible encoding and a Status

Example
buf, status := ReadFileWithEncoding(helloWorldGzip, nil)
fmt.Printf("test: ReadFileWithEncoding(\"%v\",nil) -> [buf:%v] [status:%v]\n", helloWorldGzip, string(buf), status)

h := make(http.Header)
h.Set(ContentEncoding, GzipEncoding)
buf, status = ReadFileWithEncoding(helloWorldGzip, h)
fmt.Printf("test: ReadFileWithEncoding(\"%v\",h) -> [buf:%v] [status:%v]\n", helloWorldGzip, string(buf), status)

buf, status = ReadFileWithEncoding(helloWorldTxt, nil)
fmt.Printf("test: ReadFileWithEncoding(\"%v\",nil) -> [buf:%v] [status:%v]\n", helloWorldTxt, string(buf), status)
Output:

test: ReadFileWithEncoding("file://[cwd]/test/hello-world.gz",nil) -> [buf:Hello World!!] [status:OK]
test: ReadFileWithEncoding("file://[cwd]/test/hello-world.gz",h) -> [buf:Hello World!!] [status:OK]
test: ReadFileWithEncoding("file://[cwd]/test/hello-world.txt",nil) -> [buf:Hello World!!] [status:OK]

func ValidateUri

func ValidateUri(uri string) *core.Status

func ZipFile

func ZipFile(uri string) *core.Status
Example
status := ZipFile(helloWorldTxt)

fmt.Printf("test: ZipFile(\"\") -> [status:%v]\n", status)
Output:

test: ZipFile("") -> [status:OK]

Types

type EncodingReader

type EncodingReader interface {
	io.ReadCloser
}

func NewEncodingReader

func NewEncodingReader(r io.Reader, h http.Header) (EncodingReader, *core.Status)

func NewGzipReader

func NewGzipReader(r io.Reader) (EncodingReader, *core.Status)

func NewIdentityReader

func NewIdentityReader(r io.Reader) EncodingReader

NewIdentityReader - The default (identity) encoding; the use of no transformation whatsoever

type EncodingWriter

type EncodingWriter interface {
	io.WriteCloser
	ContentEncoding() string
}

func NewEncodingWriter

func NewEncodingWriter(w io.Writer, h http.Header) (EncodingWriter, *core.Status)

func NewGzipWriter

func NewGzipWriter(w io.Writer) EncodingWriter

func NewIdentityWriter

func NewIdentityWriter(w io.Writer) EncodingWriter

NewIdentityWriter - The default (identity) encoding; the use of no transformation whatsoever

Jump to

Keyboard shortcuts

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