Documentation ¶
Overview ¶
Example ¶
// Create a buffer to write our archive to. buf := new(bytes.Buffer) // Create a new siva archive. w := siva.NewWriter(buf) // Add some files to the archive. var files = []struct { Name, Body string }{ {"readme.txt", "This archive contains some text files."}, {"gopher.txt", "Gopher names:\nGeorge\nGeoffrey\nGonzo"}, {"todo.txt", "Get animal handling license."}, } for _, file := range files { hdr := &siva.Header{ Name: file.Name, Mode: 0600, ModTime: time.Now(), } if err := w.WriteHeader(hdr); err != nil { log.Fatalln(err) } if _, err := w.Write([]byte(file.Body)); err != nil { log.Fatalln(err) } } // Make sure to check the error on Close. if err := w.Close(); err != nil { log.Fatalln(err) } // Open the siva archive for reading. file := bytes.NewReader(buf.Bytes()) r := siva.NewReader(file) // Get all the files in the siva file. i, err := r.Index() if err != nil { log.Fatalln(err) } // Iterate through the files in the archive. for _, e := range i { content, err := r.Get(e) if err != nil { log.Fatalln(err) } fmt.Printf("Contents of %s:\n", e.Name) if _, err := io.Copy(os.Stdout, content); err != nil { log.Fatalln(err) } fmt.Println() }
Output: Contents of readme.txt: This archive contains some text files. Contents of gopher.txt: Gopher names: George Geoffrey Gonzo Contents of todo.txt: Get animal handling license.
Index ¶
Examples ¶
Constants ¶
const (
IndexVersion uint8 = 1
)
Variables ¶
var ( IndexSignature = []byte{'I', 'B', 'A'} ErrInvalidIndexEntry = errors.New("invalid index entry") ErrInvalidSignature = errors.New("invalid signature") ErrEmptyIndex = errors.New("empty index") ErrUnsupportedIndexVersion = errors.New("unsupported index version") ErrCRC32Missmatch = errors.New("crc32 missmatch") )
var ( ErrPendingContent = errors.New("entry wasn't fully read") ErrInvalidCheckshum = errors.New("invalid checksum") ErrInvalidReaderAt = errors.New("reader provided doen't implements ReaderAt interface") )
var ( ErrMissingHeader = errors.New("WriteHeader was not called, or already flushed") ErrClosedWriter = errors.New("Writer is closed") )
Functions ¶
This section is empty.
Types ¶
type Index ¶
type Index []*IndexEntry
Index contains all the files on a siva file, including duplicate files or even does flagged as deleted
func (*Index) Filter ¶
Filter returns a filtered version of the current Index removing duplicates keeping the latests versions and filtering all the deleted files
func (Index) Find ¶
func (i Index) Find(name string) *IndexEntry
Find returns the first IndexEntry with the given name, if any
type IndexEntry ¶
type IndexEntry struct { Header Start uint64 Size uint64 CRC32 uint32 // contains filtered or unexported fields }
type IndexFooter ¶
type IndexFooter struct {}
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
A Reader provides random access to the contents of a siva archive.
func NewReader ¶
func NewReader(r io.ReadSeeker) *Reader
NewReader creates a new Reader reading from r, reader requires be seekable and optionally should implement io.ReaderAt to make usage of the Get method
func (*Reader) Get ¶
func (r *Reader) Get(e *IndexEntry) (*io.SectionReader, error)
Get returns a new io.SectionReader allowing concurrent read access to the content of the read
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
A Writer provides sequential writing of a siva archive
func (*Writer) Close ¶
Close closes the siva archive, writing the Index footer to the current writer.
func (*Writer) Write ¶
Write writes to the current entry in the siva archive, WriteHeader should called before, if not returns ErrMissingHeader
func (*Writer) WriteHeader ¶
WriteHeader writes hdr and prepares to accept the file's contents.