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 ¶
Exported Constants
Variables ¶
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 ¶
NewFile returns a File with the passed filename and Reader.
func (*File) GetReader ¶
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.
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) Open ¶
Open is used to get the File struct for the given filename. The underlying Reader can be used to read contents from a file.
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 ¶
Add method is used to add a File to the Dibba File system. Returns error if a file of the same name already exists.
Source Files
¶
- errors.go
- file.go
- reader.go
- section_reader.go
- writer.go