Documentation ¶
Overview ¶
Package indexpack provides an interface to a collection of compilation units stored in an "index pack" directory structure. The index pack format is defined in kythe-index-pack.txt.
Example usage, writing:
pack, err := indexpack.Create(ctx, "path/to/some/directory") if err != nil { log.Exit(err) } for _, cu := range fetchUnits() { if _, err := pack.WriteUnit(ctx, "kythe", cu); err != nil { log.Error(err) continue } for _, input := range cu.RequiredInput { data, err := readFile(input) if err != nil { log.Error(err) continue } if err := pack.WriteFile(ctx, data); err != nil { log.Error(err) } } }
Example usage, reading:
pack, err := indexpack.Open(ctx, "some/dir/path", indexpack.UnitType((*cpb.CompilationUnit)(nil))) if err != nil { log.Exit(err) } // The value passed to the callback will have the concrete type of // the third parameter to Open (or Create). err := pack.ReadUnits(ctx, "kythe", func(digest string, cu interface{}) error { for _, input := range cu.(*cpb.CompilationUnit).RequiredInput { bits, err := pack.ReadFile(ctx, input.Digest) if err != nil { return err } processData(bits) } return doSomethingUseful(cu) }) if err != nil { log.Exit(err) }
Index ¶
- type Archive
- func Create(ctx context.Context, path string, opts ...Option) (*Archive, error)
- func CreateOrOpen(ctx context.Context, path string, opts ...Option) (*Archive, error)
- func Open(ctx context.Context, path string, opts ...Option) (*Archive, error)
- func OpenZip(ctx context.Context, r io.ReaderAt, size int64, opts ...Option) (*Archive, error)
- func (a *Archive) Fetcher(ctx context.Context) analysis.Fetcher
- func (a *Archive) FileExists(ctx context.Context, digest string) (bool, error)
- func (a *Archive) ReadFile(ctx context.Context, digest string) ([]byte, error)
- func (a *Archive) ReadUnit(ctx context.Context, formatKey, digest string, f func(interface{}) error) error
- func (a *Archive) ReadUnits(ctx context.Context, formatKey string, f func(string, interface{}) error) error
- func (a *Archive) Root() string
- func (a *Archive) WriteFile(ctx context.Context, data []byte) (string, error)
- func (a *Archive) WriteUnit(ctx context.Context, formatKey string, cu interface{}) (string, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Archive ¶
type Archive struct {
// contains filtered or unexported fields
}
Archive represents an index pack directory.
func Create ¶
Create creates a new empty index pack at the specified path. It is an error if the path already exists.
func CreateOrOpen ¶
CreateOrOpen opens an existing index pack with the given parameters, if one exists; or if not, then attempts to create one.
func Open ¶
Open returns a handle for an existing valid index pack at the specified path. It is an error if path does not exist, or does not have the correct format.
func OpenZip ¶
OpenZip returns a read-only *Archive tied to the ZIP file at r, whose size in bytes is given. The ZIP file is expected to contain the recursive contents of an indexpack directory and its subdirectories. Operations that write to the pack will return errors.
func (*Archive) FileExists ¶
FileExists determines whether a file with the given digest exists.
func (*Archive) ReadFile ¶
ReadFile reads and returns the file contents corresponding to the given hex-encoded SHA-256 digest.
func (*Archive) ReadUnit ¶
func (a *Archive) ReadUnit(ctx context.Context, formatKey, digest string, f func(interface{}) error) error
ReadUnit calls f with the compilation unit stored in the units subdirectory with the given formatKey and digest. The concrete type of the value passed to f will be the same as the concrete type of the UnitType option that was passed to Open or Create. If no UnitType was specified, the value is a json.RawMessage.
If f returns a non-nil error, it is returned.
func (*Archive) ReadUnits ¶
func (a *Archive) ReadUnits(ctx context.Context, formatKey string, f func(string, interface{}) error) error
ReadUnits calls f with the digest and content of each compilation unit stored in the units subdirectory of the index pack whose format key equals formatKey. The concrete type of the value passed to f will be the same as the concrete type of the UnitType option that was passed to Open or Create. If no UnitType was specified, the value is a json.RawMessage.
If f returns a non-nil error, no further compilations are read and the error is propagated back to the caller of ReadUnits.
func (*Archive) WriteFile ¶
WriteFile writes the specified file contents to the files/ subdirectory of the index pack. Returns the resulting filename, whether or not there is an error in writing the file.
type Option ¶
An Option is a configurable setting for an Archive.