stat

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2020 License: MIT Imports: 11 Imported by: 17

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stats

type Stats struct {
	// LineCnt returns the file line count.
	LineCnt int64 `json:"linecnt" uri:"linecnt"`

	// ByteCount returns uncompressed raw file byte count.
	ByteCnt int64 `json:"bytecnt" uri:"bytecnt"`

	// Size holds the actual file size.
	Size int64 `json:"size" uri:"size"`

	// Checksum returns the base64 encoded string of the file md5 hash.
	Checksum string `json:"checksum" uri:"checksum"`

	// Path returns the full absolute path of the file.
	Path string `json:"path" uri:"origin"`

	// Created returns the date the file was created or last updated;
	// whichever is more recent.
	Created string `json:"created" uri:"created"`

	IsDir bool `json:"-"`
	// contains filtered or unexported fields
}

func New

func New() Stats
Example
sts := New()
fmt.Println(sts.LineCnt)  // output: 0
fmt.Println(sts.ByteCnt)  // output: 0
fmt.Println(sts.Size)     // output: 0
fmt.Println(sts.Checksum) // output:
fmt.Println(sts.Path)     // output:
fmt.Println(sts.Created)  // output:
Output:

0
0
0

func NewFromBytes

func NewFromBytes(b []byte) Stats

NewFromBytes creates Stats from json bytes.

Example
sts := NewFromBytes([]byte(`{"linecnt":10,"bytecnt":100,"size":200,"checksum":"test checksum","path":"test path","created":"test created"}`))
fmt.Println(sts.LineCnt)  // output: 10
fmt.Println(sts.ByteCnt)  // output: 100
fmt.Println(sts.Size)     // output: 200
fmt.Println(sts.Checksum) // output: test checksum
fmt.Println(sts.Path)     // output: test path
fmt.Println(sts.Created)  // output: test created
Output:

10
100
200
test checksum
test path
test created

func NewFromInfo

func NewFromInfo(info string) Stats

NewFromInfo creates Stats from a uri formatted info string.

func (*Stats) AddBytes

func (s *Stats) AddBytes(cnt int64)

AddBytes will atomically and safely increment ByteCnt by 'cnt'.

func (*Stats) AddLine

func (s *Stats) AddLine()

AddLine will atomically and safely increment LineCnt by one.

func (Stats) Clone

func (s Stats) Clone() Stats

Clone will create a copy of stat that won't trigger race conditions. Use Clone if you are updating and reading from stats at the same time. Read from the clone.

func (Stats) InfoString

func (s Stats) InfoString() string

InfoString creates a uri-style info string from Stats.

func (Stats) JSONBytes

func (s Stats) JSONBytes() []byte

func (Stats) JSONString

func (s Stats) JSONString() string

func (*Stats) ParseCreated

func (s *Stats) ParseCreated() time.Time

ParseCreated will attempt to parse the Created field to a time.Time object. ParseCreated expects the Created time string is in time.RFC3339. If there is a parse error then the time.Time zero value is returned.

The returned time will always be in UTC.

func (Stats) ParsePath

func (s Stats) ParsePath() (scheme, host, fPth string)

func (*Stats) SetChecksum

func (s *Stats) SetChecksum(hsh hash.Hash)

SetChecksum will correctly calculate and set the base64 encoded checksum.

func (*Stats) SetCreated

func (s *Stats) SetCreated(t time.Time)

SetCreated will set the Created field in the format time.RFC3339 in UTC.

func (*Stats) SetPath

func (s *Stats) SetPath(pth string)

func (*Stats) SetSize

func (s *Stats) SetSize(size int64)

Jump to

Keyboard shortcuts

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