fileinfo

package module
v0.0.0-...-435135a Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2018 License: MIT Imports: 12 Imported by: 0

README

File Info

Build Status codecov GoDoc Go Report Card

A go package that extracts and stores basic metadata about a file.

Installation

Assuming a correctly configured Go toolchain:

go get github.com/cpliakas/fileinfo

Usage

The code below writes a file's MD5 sum to STDOUT.

package main

import (
	"fmt"

	"github.com/cpliakas/fileinfo"
)

func main() {
	i, err := fileinfo.New("/path/to/file")
	if err != nil {
		panic(err)
	}
	defer i.Close()

	h, _ := i.Hash()
	fmt.Println(h)
}

Documentation

Overview

Package fileinfo extracts and stores basic metadata about a file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fileinfo

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

Fileinfo extracts information about the passed file.

func New

func New(fname string) (i *Fileinfo, err error)

New returns a new Fileinfo populated with the named file opened for reading.

func (*Fileinfo) Basename

func (i *Fileinfo) Basename() string

Basename returns the basename of the file.

func (*Fileinfo) Close

func (i *Fileinfo) Close() error

Close closes the file, rendering it unusable for I/O.

func (*Fileinfo) FirstBytes

func (i *Fileinfo) FirstBytes() (bytes string, err error)

FirstBytes returns the first 32 bytes of a file, base64 encoded.

func (*Fileinfo) Hash

func (i *Fileinfo) Hash() (hash string, err error)

Hash returns the file's MD5 sum.

func (*Fileinfo) LastBytes

func (i *Fileinfo) LastBytes() (bytes string, err error)

LastBytes returns the last 32 bytes of a file, base64 encoded.

func (*Fileinfo) Name

func (i *Fileinfo) Name() string

Name returns the file name.

func (*Fileinfo) Size

func (i *Fileinfo) Size() int64

Size returns the size of the file in bytes.

func (*Fileinfo) Type

func (i *Fileinfo) Type() (typ string, err error)

Type returns the mime type.

type Storage

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

Storage saves information about a file in a SQLite database.

func NewStorage

func NewStorage(dbfile string) (s *Storage, err error)

NewStorage returns a *Storage with an initialized SQLite database and open connection to it.

func (Storage) Close

func (s Storage) Close() error

Close closes the connection to the SQLite database.

func (Storage) Save

func (s Storage) Save(i *Fileinfo) (err error)

Save saves the file info in the SQLite database.

func (Storage) Truncate

func (s Storage) Truncate() (err error)

Truncate drops all data from the files table.

Jump to

Keyboard shortcuts

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