storj/pkg/filepiece
Alexander Leitner 5e97cf7a2e Moved filepiece into storj (#66)
* Moved filepiece into storj

* Fix linter errors

* Seek comment for linter

* gofmt/golinter accidentally removed import

* Fix small typos

* Use the weird iota. P cool dude ✌️

* Do things the cool way

* Changes requested by kaloyan

* didn't need test main
2018-05-31 22:42:45 +03:00
..
fpiece_test.go Moved filepiece into storj (#66) 2018-05-31 22:42:45 +03:00
fpiece.go Moved filepiece into storj (#66) 2018-05-31 22:42:45 +03:00
README.md Moved filepiece into storj (#66) 2018-05-31 22:42:45 +03:00

FilePiece

Concurrently read and write from files

Installation

go get storj.io/storj/pkg/filepiece

Usage

import "storj.io/storj/pkg/filepiece"

Chunk struct

type Chunk struct {
	file       *os.File
	offset     int64
	length     int64
	currentPos int64
}
  • Chunk.file - os.File being read from
  • Chunk.offset - starting position for reading/writing data
  • Chunk.length - length of data to be read/written
  • Chunk.currentPos - Keeps track to know where to write to or read from next

NewChunk

Create a chunk from a file

func NewChunk(file *os.File, offset int64, length int64) (*Chunk, error)

Read

Concurrently read from a file

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

Write

Concurrently write to a file

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

Other

Get the size of the Chunk

func (f *Chunk) Size() int64

Close the Chunk File

func (f *Chunk) Close() error

Seek to certain position of Chunk

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