项目作者: src-d

项目描述 :
siva - seekable indexed verifiable archiver
高级语言: Go
项目地址: git://github.com/src-d/go-siva.git
创建时间: 2016-09-29T12:34:40Z
项目社区:https://github.com/src-d/go-siva

开源协议:MIT License

下载


siva format GoDoc Build Status Build status codebeat badge

siva stand for seekable indexed verifiable archiver

siva is archive format very similar to tar or zip, focused on allowing: constant-time random file access, seekable access to the contained files and concatenable archive files

siva

The library implements a very similar API to the go tar package, allowing full control over and low level access to the contained files.

Installation

The recommended way to install siva

  1. go get -u gopkg.in/src-d/go-siva.v1/...

Example

Creating a siva file:

  1. // Create a buffer to write our archive to.
  2. buf := new(bytes.Buffer)
  3. // Create a new siva archive.
  4. w := siva.NewWriter(buf)
  5. // Add some files to the archive.
  6. var files = []struct {
  7. Name, Body string
  8. }{
  9. {"readme.txt", "This archive contains some text files."},
  10. {"gopher.txt", "Gopher names:\nGeorge\nGeoffrey\nGonzo"},
  11. {"todo.txt", "Get animal handling license."},
  12. }
  13. for _, file := range files {
  14. hdr := &siva.Header{
  15. Name: file.Name,
  16. Mode: 0600,
  17. ModTime: time.Now(),
  18. }
  19. if err := w.WriteHeader(hdr); err != nil {
  20. log.Fatalln(err)
  21. }
  22. if _, err := w.Write([]byte(file.Body)); err != nil {
  23. log.Fatalln(err)
  24. }
  25. }
  26. // Make sure to check the error on Close.
  27. if err := w.Close(); err != nil {
  28. log.Fatalln(err)
  29. }

Reading from a siva file:

  1. // Open the siva archive for reading.
  2. file := bytes.NewReader(buf.Bytes())
  3. r := siva.NewReader(file)
  4. // Get all the files in the siva file.
  5. i, err := r.Index()
  6. if err != nil {
  7. log.Fatalln(err)
  8. }
  9. // Iterate through the files in the archive.
  10. for _, e := range i {
  11. content, err := r.Get(e)
  12. if err != nil {
  13. log.Fatalln(err)
  14. }
  15. fmt.Printf("Contents of %s:\n", e.Name)
  16. if _, err := io.Copy(os.Stdout, content); err != nil {
  17. log.Fatalln(err)
  18. }
  19. fmt.Println()
  20. }

Command-line interface" class="reference-link">Command-line interface

siva cli interface, is a convenient command that helps you to creates and manipulates siva files.

Output from: ./siva --help:

  1. Usage:
  2. siva [OPTIONS] <command>
  3. Help Options:
  4. -h, --help Show this help message
  5. Available commands:
  6. list List the items contained on a file.
  7. pack Create a new archive containing the specified items.
  8. unpack Extract to disk from the archive.
  9. version Show the version information.

Other comments

  • The Index Signature is specified as a sequence of 3 bytes. Go uses byte as an alias for uint8.
  • File Mode in an Index entry, see issue.
  • This implementation left in the client of the library side the task of check the integrity of the file contents. It just checks for the Index integrity.

License

MIT, see LICENSE