mscfb

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2022 License: Apache-2.0 Imports: 8 Imported by: 126

README

A reader for Microsoft's Compound File Binary File Format.

Example usage:

file, _ := os.Open("test/test.doc")
defer file.Close()
doc, err := mscfb.New(file)
if err != nil {
  log.Fatal(err)
}
for entry, err := doc.Next(); err == nil; entry, err = doc.Next() {
  buf := make([]byte, 512)
  i, _ := doc.Read(buf)
  if i > 0 {
    fmt.Println(buf[:i])
  }
  fmt.Println(entry.Name)
}

The Compound File Binary File Format is also known as the Object Linking and Embedding (OLE) or Component Object Model (COM) format and was used by early MS software such as MS Office. See http://msdn.microsoft.com/en-us/library/dd942138.aspx for more details

Install with go get github.com/richardlehane/mscfb

Build Status

Documentation

Overview

Package mscfb implements a reader for Microsoft's Compound File Binary File Format (http://msdn.microsoft.com/en-us/library/dd942138.aspx).

The Compound File Binary File Format is also known as the Object Linking and Embedding (OLE) or Component Object Model (COM) format and was used by many early MS software such as MS Office.

Example:

file, _ := os.Open("test/test.doc")
defer file.Close()
doc, err := mscfb.New(file)
if err != nil {
  log.Fatal(err)
}
for entry, err := doc.Next(); err == nil; entry, err = doc.Next() {
  buf := make([]byte, 512)
  i, _ := entry.Read(buf)
  if i > 0 {
    fmt.Println(buf[:i])
  }
  fmt.Println(entry.Name)
}

Index

Constants

View Source
const (
	// ErrFormat reports issues with the MSCFB's header structures
	ErrFormat = iota
	// ErrRead reports issues attempting to read MSCFB streams
	ErrRead
	// ErrSeek reports seek issues
	ErrSeek
	// ErrWrite reports write issues
	ErrWrite
	// ErrTraverse reports issues attempting to traverse the child-parent-sibling relations
	// between MSCFB storage objects
	ErrTraverse
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

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

func (Error) Error

func (e Error) Error() string

func (Error) Typ

func (e Error) Typ() int

Typ gives the type of MSCFB error

type File

type File struct {
	Name    string   // stream or directory name
	Initial uint16   // the first character in the name (identifies special streams such as MSOLEPS property sets)
	Path    []string // file path
	Size    int64    // size of stream
	// contains filtered or unexported fields
}

File represents a MSCFB directory entry

func (*File) Created

func (f *File) Created() time.Time

Created returns this directory entry's created field

func (*File) FileInfo

func (f *File) FileInfo() os.FileInfo

FileInfo for this directory entry. Useful for IsDir() (whether a directory entry is a stream (file) or a storage object (dir))

func (*File) ID

func (f *File) ID() string

ID returns this directory entry's CLSID field

func (*File) Modified

func (f *File) Modified() time.Time

Created returns this directory entry's modified field

func (*File) Read

func (f *File) Read(b []byte) (int, error)

Read this directory entry Returns 0, io.EOF if no stream is available (i.e. for a storage object)

func (*File) ReadAt

func (f *File) ReadAt(p []byte, off int64) (n int, err error)

ReadAt reads p bytes at offset off from start of file. Does not affect seek place for other reads/writes.

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

Seek sets the offset for the next Read or Write to offset, interpreted according to whence: 0 means relative to the start of the file, 1 means relative to the current offset, and 2 means relative to the end. Seek returns the new offset relative to the start of the file and an error, if any.

func (*File) Write

func (f *File) Write(b []byte) (int, error)

Write to this directory entry Depends on the io.ReaderAt supplied to mscfb.New() being a WriterAt too Returns 0, io.EOF if no stream is available (i.e. for a storage object)

func (*File) WriteAt

func (f *File) WriteAt(p []byte, off int64) (n int, err error)

WriteAt reads p bytes at offset off from start of file. Does not affect seek place for other reads/writes.

type Reader

type Reader struct {
	File []*File // File is an ordered slice of final directory entries.
	// contains filtered or unexported fields
}

Reader provides sequential access to the contents of a MS compound file (MSCFB)

func New

func New(ra io.ReaderAt) (*Reader, error)

New returns a MSCFB reader

func (*Reader) Created

func (r *Reader) Created() time.Time

Created returns the created field from the root directory entry

func (*Reader) Debug

func (r *Reader) Debug() map[string][]uint32

Debug provides granular information from an mscfb file to assist with debugging

func (*Reader) ID

func (r *Reader) ID() string

ID returns the CLSID (class ID) field from the root directory entry

func (*Reader) Modified

func (r *Reader) Modified() time.Time

Modified returns the last modified field from the root directory entry

func (*Reader) Next

func (r *Reader) Next() (*File, error)

Next iterates to the next directory entry. This isn't necessarily an adjacent *File within the File slice, but is based on the Left Sibling, Right Sibling and Child information in directory entries.

func (*Reader) Read

func (r *Reader) Read(b []byte) (n int, err error)

Read the current directory entry

Jump to

Keyboard shortcuts

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