dibba

package module
v0.0.0-...-ee4c513 Latest Latest
Warning

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

Go to latest
Published: May 1, 2018 License: BSD-3-Clause Imports: 5 Imported by: 0

README

dibba - package format reader

Go Report Card

Dibba is a small go library for a new TLV based file format for storing just files. Refer godoc for more. See Examples for sample usage.

  • Packager : Packages files into a single dibba file.

    $ cd $GOPATH/github.com/aki237/dibba/examples/packager/
    $ go build
    $ ./packager outFile.dib example/*
    35
    4259516
    $ ls
    .  ..  example  outFile.dib  package.go  packager
    
  • Parser : Parse the dibba file and print out the contents of a given file from the package

    $ cd $GOPATH/github.com/aki237/dibba/examples/parser/
    $ go build
    $ ./parser ../packager/outFile.dib Readme.md
    # Readme
    
    This is a sample readme.
    

Documentation

Overview

Package dibba contains utility to interact with the dibba boxed documents.

Usage

This package can be used to interact with dibba file packages. All this operations are done using structs and methods that are compatible with interfaces in io package like "Reader", "Writer", "WriteSeeker" and etc.,

A sample usage is given below :

Consider inputFile is the dibbaFormat filename in the filesystem and file is the filename of a file to be opened from the dibba package. Open the file.

f, err := os.Open(inputFile)
if err != nil {
	fmt.Println(err)
	return
}

Create a new dibba.Reader using any kind of io.ReadSeeker. In this case it is *os.File.

d := dibba.NewReader(f)
err = d.Parse()
if err != nil {
	fmt.Println(err)
	return
}

From the dibba.Reader open the file.

fd, err := d.Open(file)
if err != nil {
	fmt.Println(err)
	return
}

Open returns a *dibba.File. There is a Reader inside the struct which is obtained by GetReader method.

_, err = io.Copy(os.Stdout, fd.GetReader())
if err != nil {
	fmt.Println(err)
	return
}

See the examples directory for handling dibba files using this package.

Index

Constants

View Source
const (
	TypeDibbaHeader int = iota
	TypeFile
	TypeDibbaEnder
)

Exported Constants

Variables

View Source
var (
	// ErrMalformed is returned if the given Reader is not a proper Dibba format file.
	ErrMalformed = errors.New("Malformed dibba passed")

	// ErrNoFileName is returned when no filename is specified for a given File struct.
	ErrNoFileName = errors.New("Filename not specified")

	// ErrFileAlreadyExists is returned while adding a new file to the package if a file
	// already exists in a package.
	ErrFileAlreadyExists = errors.New("File already exists")

	// ErrAlreadyCommitted is returned when Commit is called on a Writer struct again.
	ErrAlreadyCommitted = errors.New("Already committed")

	// ErrFileNotFound is returned when a given file is not found in the given package.
	ErrFileNotFound = errors.New("File not found in the Dibba")
)

Functions

This section is empty.

Types

type File

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

File is a struct denoting a Dibba file.

func NewFile

func NewFile(filename string, rd io.Reader) *File

NewFile returns a File with the passed filename and Reader.

func (*File) GetReader

func (f *File) GetReader() io.Reader

GetReader method returns the underlying io.Reader of the file.

func (*File) MarshalTo

func (f *File) MarshalTo(w io.WriteSeeker) error

MarshalTo method encodes the file contents (like in dibba file format) and writes it in a writer.

func (*File) Name

func (f *File) Name() string

Name method returns the filename of the File object

type Reader

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

Reader is used to parse and read files from a givem dibba package from the io.ReadSeeker

func NewReader

func NewReader(rd io.ReadSeeker) *Reader

NewReader is used to create new Reader instance for a given io.ReadSeeker.

func (Reader) GetFileList

func (db Reader) GetFileList() []string

func (*Reader) Open

func (db *Reader) Open(filename string) (*File, error)

Open is used to get the File struct for the given filename. The underlying Reader can be used to read contents from a file.

func (*Reader) Parse

func (db *Reader) Parse() error

Parse is used to parse the underlying io.ReadSeeker and store the filebounds.

type SectionReader

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

SectionReader is a struct obeying the io.Reader interface used to read the section of a given io.ReadSeeker (dibba.Reader).

func (*SectionReader) Read

func (s *SectionReader) Read(p []byte) (int, error)

Read is the method of SectionReader that makes it compatible with io.Reader interface. It reads only a section of a file specified in the unexported fields on the struct.

type Writer

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

Writer is used to add (write) files in a dibba package

func NewWriter

func NewWriter(ws io.WriteSeeker) *Writer

NewWriter returns Writer struct with the passed WriteSeeker as the output file.

func (*Writer) Add

func (db *Writer) Add(file *File) error

Add method is used to add a File to the Dibba File system. Returns error if a file of the same name already exists.

func (*Writer) Commit

func (db *Writer) Commit() error

Commit method is used to write all contents to a io.ReedSeeker (*os.File is compatible) including the header, contents and the ender.

Source Files

  • errors.go
  • file.go
  • reader.go
  • section_reader.go
  • writer.go

Directories

Path Synopsis
examples
packager command
parser command

Jump to

Keyboard shortcuts

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