resource

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package resource provides utility functions for handling resources from byte arrays. This package simplifies reading, streaming, and buffering byte array resources.

Package resource provides utility functions for handling resources from various input sources. This package simplifies reading, streaming, and buffering resources.

Package resource provides utility functions for handling resources from various input sources. This package simplifies reading, streaming, and buffering resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BytesResource

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

BytesResource reads resources from a byte array

func NewBytesResource

func NewBytesResource(name string, data []byte) *BytesResource

NewBytesResource creates a new BytesResource instance

Parameters: - name: the name of the resource - data: the byte array data of the resource

Returns: - *BytesResource: a new BytesResource instance

func (*BytesResource) GetName

func (r *BytesResource) GetName() string

GetName returns the name of the resource

Returns: - string: the name of the resource

func (*BytesResource) GetReader

func (r *BytesResource) GetReader(charset string) (*bufio.Reader, error)

GetReader returns a BufferedReader of the resource

Parameters: - charset: the charset to use (not used in this implementation)

Returns: - *bufio.Reader: a BufferedReader of the resource - error: if an error occurs

func (*BytesResource) GetStream

func (r *BytesResource) GetStream() (io.Reader, error)

GetStream returns an input stream of the resource

Returns: - io.Reader: an input stream of the resource - error: if an error occurs

func (*BytesResource) GetUrl

func (r *BytesResource) GetUrl() *url.URL

GetUrl returns the URL of the resource (nil in this implementation)

Returns: - *url.URL: the URL of the resource

func (*BytesResource) ReadStr

func (r *BytesResource) ReadStr(charset string) (string, error)

ReadStr reads the content of the resource as a string

Parameters: - charset: the charset to use (not used in this implementation)

Returns: - string: the content of the resource as a string - error: if an error occurs

type ReaderResource

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

ReaderResource reads resources from an io.Reader

func NewReaderResource

func NewReaderResource(name string, in io.Reader) *ReaderResource

NewReaderResource creates a new ReaderResource instance

Parameters: - name: the name of the resource - in: the io.Reader input source

Returns: - *ReaderResource: a new ReaderResource instance

func (*ReaderResource) GetName

func (r *ReaderResource) GetName() string

GetName returns the name of the resource

Returns: - string: the name of the resource

func (*ReaderResource) GetReader

func (r *ReaderResource) GetReader(charset string) (*bufio.Reader, error)

GetReader returns a BufferedReader of the resource

Parameters: - charset: the charset to use (not used in this implementation)

Returns: - *bufio.Reader: a BufferedReader of the resource - error: if an error occurs

func (*ReaderResource) GetStream

func (r *ReaderResource) GetStream() (io.Reader, error)

GetStream returns an input stream of the resource

Returns: - io.Reader: an input stream of the resource - error: if an error occurs

func (*ReaderResource) GetUrl

func (r *ReaderResource) GetUrl() *url.URL

GetUrl returns the URL of the resource (nil in this implementation)

Returns: - *url.URL: the URL of the resource

func (*ReaderResource) ReadStr

func (r *ReaderResource) ReadStr(charset string) (string, error)

ReadStr reads the content of the resource as a string

Parameters: - charset: the charset to use (not used in this implementation)

Returns: - string: the content of the resource as a string - error: if an error occurs

type Resource

type Resource interface {
	GetName() string
	GetUrl() *url.URL
	GetStream() (io.Reader, error)
	GetReader(charset string) (*bufio.Reader, error)
	ReadStr(charset string) (string, error)
}

Resource A common resource interface is defined to obtain resource flow, read text and so on

type StringResource

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

StringResource reads resources from a string

func NewStringResource

func NewStringResource(name string, data string) *StringResource

NewStringResource creates a new StringResource instance

Parameters: - name: the name of the resource - data: the string data of the resource

Returns: - *StringResource: a new StringResource instance

func (*StringResource) GetName

func (r *StringResource) GetName() string

GetName returns the name of the resource

Returns: - string: the name of the resource

func (*StringResource) GetReader

func (r *StringResource) GetReader(charset string) (*bufio.Reader, error)

GetReader returns a BufferedReader of the resource

Parameters: - charset: the charset to use (not used in this implementation)

Returns: - *bufio.Reader: a BufferedReader of the resource - error: if an error occurs

func (*StringResource) GetStream

func (r *StringResource) GetStream() (io.Reader, error)

GetStream returns an input stream of the resource

Returns: - io.Reader: an input stream of the resource - error: if an error occurs

func (*StringResource) GetUrl

func (r *StringResource) GetUrl() *url.URL

GetUrl returns the URL of the resource (nil in this implementation)

Returns: - *url.URL: the URL of the resource

func (*StringResource) ReadStr

func (r *StringResource) ReadStr(charset string) (string, error)

ReadStr reads the content of the resource as a string

Parameters: - charset: the charset to use (not used in this implementation)

Returns: - string: the content of the resource as a string - error: if an error occurs

Jump to

Keyboard shortcuts

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