Documentation
¶
Overview ¶
Package encoder creates pxar archives.
Encoder writes pxar archive entries in a single sequential pass. It supports both unified (v1) and split (v2) formats via separate io.Writer outputs.
Usage ¶
enc := encoder.NewEncoder(output, nil, &rootMeta, nil)
enc.AddFile(&fileMeta, "hello.txt", []byte("hello world"))
enc.Close()
For split archives, provide a payload writer to NewEncoder and file content is written to the payload stream with PAYLOAD_REF entries in the metadata stream.
Directory Nesting ¶
Directories are created with CreateDirectory and finalized with Finish. The encoder maintains a state stack, so Finish closes the most recently opened directory and resumes the parent's context. Close finalizes the root directory and writes the goodbye table.
Hardlinks ¶
AddFile and AddPayloadRef return a LinkOffset token. Pass this token to AddHardlink to create a hardlink that references the original file via a relative offset in the wire format.
Streaming Files ¶
For large files, use CreateFile to obtain a *FileWriter (io.Writer). Write content via io.Copy or direct writes, then call Close on the writer.
Payload References ¶
AddPayloadRef writes a PAYLOAD_REF entry pointing to existing payload data without writing the content. Use PayloadPosition and Advance to track virtual payload positions for external chunk injection.
Package encoder creates pxar archives.
Index ¶
- type Encoder
- func (e *Encoder) AddDevice(metadata *pxar.Metadata, name string, device format.Device) error
- func (e *Encoder) AddFIFO(metadata *pxar.Metadata, name string) error
- func (e *Encoder) AddFile(metadata *pxar.Metadata, name string, content []byte) (LinkOffset, error)
- func (e *Encoder) AddHardlink(name string, target string, targetOffset LinkOffset) error
- func (e *Encoder) AddPayloadRef(metadata *pxar.Metadata, name string, fileSize uint64, payloadOffset uint64) (LinkOffset, error)
- func (e *Encoder) AddSocket(metadata *pxar.Metadata, name string) error
- func (e *Encoder) AddSymlink(metadata *pxar.Metadata, name string, target string) error
- func (e *Encoder) Advance(size uint64) error
- func (e *Encoder) Close() error
- func (e *Encoder) CreateDirectory(name string, metadata *pxar.Metadata) error
- func (e *Encoder) CreateFile(metadata *pxar.Metadata, name string, size uint64) (*FileWriter, error)
- func (e *Encoder) Finish() error
- func (e *Encoder) PayloadPosition() uint64
- type FileWriter
- type LinkOffset
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder writes pxar archives.
func NewEncoder ¶
NewEncoder creates a new pxar encoder writing to the given writers. If payloadOut is non-nil, the archive is split (v2 format). metadata describes the root directory. prelude is optional v2 prelude data.
func (*Encoder) AddHardlink ¶
func (e *Encoder) AddHardlink(name string, target string, targetOffset LinkOffset) error
AddHardlink adds a hard link.
func (*Encoder) AddPayloadRef ¶ added in v0.17.0
func (e *Encoder) AddPayloadRef(metadata *pxar.Metadata, name string, fileSize uint64, payloadOffset uint64) (LinkOffset, error)
AddPayloadRef adds a file entry that references existing payload data. It writes the metadata entry (filename + stat + PXAR_PAYLOAD_REF) but does NOT write any real payload data. Instead, it writes a PXAR_PAYLOAD header + zero-fill to maintain correct offsets in the payload stream. The caller is responsible for ensuring the original payload chunks are available in the datastore (either via injection or dedup).
func (*Encoder) AddSymlink ¶
AddSymlink adds a symbolic link.
func (*Encoder) Advance ¶ added in v0.17.0
Advance advances the payload write position by the given size. This is used with AddPayloadRef to track the virtual payload size without actually writing payload data.
func (*Encoder) CreateDirectory ¶
CreateDirectory pushes a new directory onto the stack.
func (*Encoder) CreateFile ¶
func (e *Encoder) CreateFile(metadata *pxar.Metadata, name string, size uint64) (*FileWriter, error)
CreateFile returns a FileWriter for streaming file content.
func (*Encoder) PayloadPosition ¶ added in v0.17.0
PayloadPosition returns the current write position in the payload stream.
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
FileWriter writes file content to a pxar archive.
func (*FileWriter) FileOffset ¶
func (fw *FileWriter) FileOffset() LinkOffset
FileOffset returns the file's offset for use with AddHardlink.
func (*FileWriter) Write ¶
func (fw *FileWriter) Write(data []byte) (int, error)
Write writes data to the file.
func (*FileWriter) WriteAll ¶
func (fw *FileWriter) WriteAll(data []byte) error
WriteAll writes all data to the file.
type LinkOffset ¶
type LinkOffset uint64
LinkOffset represents a file offset usable with AddHardlink.