Documentation ¶
Index ¶
- Variables
- type Algorithm
- func (a Algorithm) DetectHeader(h []byte) bool
- func (a Algorithm) Extension() string
- func (a Algorithm) IsNone() bool
- func (a Algorithm) MarshalJSON() ([]byte, error)
- func (a Algorithm) MarshalText() ([]byte, error)
- func (a Algorithm) Reader(r io.ReadCloser) (arctps.Reader, error)
- func (a Algorithm) String() string
- func (a *Algorithm) UnmarshalJSON(b []byte) error
- func (a *Algorithm) UnmarshalText(b []byte) error
- func (a Algorithm) Writer(w io.WriteCloser) (arctps.Writer, error)
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidAlgorithm = errors.New("invalid algorithm")
)
Functions ¶
This section is empty.
Types ¶
type Algorithm ¶ added in v1.15.0
type Algorithm uint8
func Detect ¶ added in v1.15.0
func Detect(r io.ReadCloser) (Algorithm, arctps.Reader, io.ReadCloser, error)
Detect will try to detect the algorithm of the input and returns the corresponding reader. This function will read the first 6 bytes of the input and try to detect the algorithm. If algorithm detection trigger a supported algorithm, the function will try to convert the input to appropriate reader for the archive. In any case, if en error occurs, the function will return an error. Otherwise, the function will return the algorithm, the reader and a nil error.
If the input is a zip archive and the input is not a io.ReaderAt compatible, the function will return. If the input is a tar archive and the input is a strict io.ReadCloser, with no seek or read at compatible, the reader result could be use only for one time.
This difference are based on how the algorithm work: - zip: will use dictionary / catalog to store position and metadata of each embedded file - tar: (TAR = Tape ARchive) will store each file continuously beginning with his metadata and following with his content.
As that, a strict reader could be use only for tar archive and the reader result could be use only for one time. In this case, the best use if calling the walk function of the reader.