Documentation
¶
Index ¶
- Constants
- Variables
- func AckReadThread()
- func AckWriteThread()
- func CheckHash(hash string) bool
- func CheckHashErr(hash string) error
- func EncodeMetaBlock(action MetaAction, hash string, data []byte) ([]byte, error)
- func Hash(s string) string
- func IsEnabled() bool
- func IsNotExist(err error) bool
- func IsWritingErr(err error) bool
- func ReleaseReadThread()
- func ReleaseWriteThread()
- type BlockFileOptions
- type BlockInfo
- type BlockType
- type BlocksFile
- func (this *BlocksFile) CanClose() bool
- func (this *BlocksFile) Close() error
- func (this *BlocksFile) CloseFileReader(reader *FileReader) error
- func (this *BlocksFile) Compact() error
- func (this *BlocksFile) DecrRef()
- func (this *BlocksFile) ExistFile(fileHash string) bool
- func (this *BlocksFile) Filename() string
- func (this *BlocksFile) ForceSync() error
- func (this *BlocksFile) IncrRef()
- func (this *BlocksFile) IsClosing() bool
- func (this *BlocksFile) OpenFileReader(fileHash string, isPartial bool) (*FileReader, error)
- func (this *BlocksFile) OpenFileWriter(fileHash string, bodySize int64, isPartial bool) (writer *FileWriter, err error)
- func (this *BlocksFile) RemoveAll() error
- func (this *BlocksFile) RemoveFile(fileHash string) error
- func (this *BlocksFile) Sync() error
- func (this *BlocksFile) SyncAt() time.Time
- func (this *BlocksFile) TestReaderPool() chan *FileReader
- func (this *BlocksFile) Write(hash string, blockType BlockType, b []byte, originOffset int64) (n int, err error)
- type FS
- func (this *FS) Close() error
- func (this *FS) ExistFile(hash string) (bool, error)
- func (this *FS) OpenFileReader(hash string, isPartial bool) (*FileReader, error)
- func (this *FS) OpenFileWriter(hash string, bodySize int64, isPartial bool) (*FileWriter, error)
- func (this *FS) RemoveFile(hash string) error
- func (this *FS) TestBList() *linkedlist.List[string]
- func (this *FS) TestBMap() map[string]*BlocksFile
- type FSOptions
- type FileHeader
- type FileReader
- func (this *FileReader) Close() error
- func (this *FileReader) FileHeader() *FileHeader
- func (this *FileReader) Free() error
- func (this *FileReader) Read(b []byte) (n int, err error)
- func (this *FileReader) ReadAt(b []byte, offset int64) (n int, err error)
- func (this *FileReader) Reset(fileHeader *FileHeader)
- type FileWriter
- func (this *FileWriter) Close() error
- func (this *FileWriter) Discard() error
- func (this *FileWriter) WriteBody(b []byte) (n int, err error)
- func (this *FileWriter) WriteBodyAt(b []byte, offset int64) (n int, err error)
- func (this *FileWriter) WriteHeader(b []byte) (n int, err error)
- func (this *FileWriter) WriteMeta(status int, expiresAt int64, expectedFileSize int64) error
- type GzipReaderPool
- type GzipWriterPool
- type LazyFileHeader
- type MetaAction
- type MetaFile
- func (this *MetaFile) CloneFileHeader(hash string) (header *FileHeader, ok bool)
- func (this *MetaFile) Close() error
- func (this *MetaFile) Compact() error
- func (this *MetaFile) ExistFile(hash string) bool
- func (this *MetaFile) FileHeader(hash string) (header *FileHeader, ok bool)
- func (this *MetaFile) FileHeaderUnsafe(hash string) (header *FileHeader, ok bool)
- func (this *MetaFile) FileHeaders() map[string]*LazyFileHeader
- func (this *MetaFile) RemoveAll() error
- func (this *MetaFile) RemoveFile(hash string) error
- func (this *MetaFile) SyncUnsafe() error
- func (this *MetaFile) WriteBodyBlockUnsafe(hash string, bOffsetFrom int64, bOffsetTo int64, originOffsetFrom int64, ...) error
- func (this *MetaFile) WriteClose(hash string, headerSize int64, bodySize int64) error
- func (this *MetaFile) WriteHeaderBlockUnsafe(hash string, bOffsetFrom int64, bOffsetTo int64) error
- func (this *MetaFile) WriteMeta(hash string, status int, expiresAt int64, expectedFileSize int64) error
Constants ¶
View Source
const BFileExt = ".b"
View Source
const MFileExt = ".m"
View Source
const Version1 = 1
Variables ¶
View Source
var DefaultBlockFileOptions = &BlockFileOptions{
BytesPerSync: 1 << 20,
}
View Source
var DefaultFSOptions = &FSOptions{ MaxOpenFiles: 1 << 10, BytesPerSync: 512 << 10, SyncTimeout: 1 * time.Second, MaxSyncFiles: 32, }
View Source
var ErrClosed = errors.New("the file closed")
View Source
var ErrFileIsWriting = errors.New("the file is writing")
View Source
var ErrInvalidHash = errors.New("invalid hash")
View Source
var HashLen = 32
Functions ¶
func AckReadThread ¶
func AckReadThread()
func AckWriteThread ¶
func AckWriteThread()
func CheckHashErr ¶
func EncodeMetaBlock ¶
func EncodeMetaBlock(action MetaAction, hash string, data []byte) ([]byte, error)
func IsNotExist ¶
func IsWritingErr ¶
func ReleaseReadThread ¶
func ReleaseReadThread()
func ReleaseWriteThread ¶
func ReleaseWriteThread()
Types ¶
type BlockFileOptions ¶
type BlockFileOptions struct {
BytesPerSync int64
}
func (*BlockFileOptions) EnsureDefaults ¶
func (this *BlockFileOptions) EnsureDefaults()
type BlockInfo ¶
type BlocksFile ¶
type BlocksFile struct {
// contains filtered or unexported fields
}
func NewBlocksFileWithRawFile ¶
func NewBlocksFileWithRawFile(fp *os.File, options *BlockFileOptions) (*BlocksFile, error)
func OpenBlocksFile ¶
func OpenBlocksFile(filename string, options *BlockFileOptions) (*BlocksFile, error)
func (*BlocksFile) CloseFileReader ¶
func (this *BlocksFile) CloseFileReader(reader *FileReader) error
func (*BlocksFile) Compact ¶
func (this *BlocksFile) Compact() error
func (*BlocksFile) DecrRef ¶
func (this *BlocksFile) DecrRef()
func (*BlocksFile) ExistFile ¶
func (this *BlocksFile) ExistFile(fileHash string) bool
func (*BlocksFile) Filename ¶
func (this *BlocksFile) Filename() string
func (*BlocksFile) ForceSync ¶
func (this *BlocksFile) ForceSync() error
func (*BlocksFile) IncrRef ¶
func (this *BlocksFile) IncrRef()
func (*BlocksFile) OpenFileReader ¶
func (this *BlocksFile) OpenFileReader(fileHash string, isPartial bool) (*FileReader, error)
func (*BlocksFile) OpenFileWriter ¶
func (this *BlocksFile) OpenFileWriter(fileHash string, bodySize int64, isPartial bool) (writer *FileWriter, err error)
func (*BlocksFile) RemoveAll ¶
func (this *BlocksFile) RemoveAll() error
func (*BlocksFile) RemoveFile ¶
func (this *BlocksFile) RemoveFile(fileHash string) error
func (*BlocksFile) Sync ¶
func (this *BlocksFile) Sync() error
func (*BlocksFile) SyncAt ¶
func (this *BlocksFile) SyncAt() time.Time
func (*BlocksFile) TestReaderPool ¶
func (this *BlocksFile) TestReaderPool() chan *FileReader
type FS ¶
type FS struct {
// contains filtered or unexported fields
}
FS 文件系统对象
func (*FS) OpenFileReader ¶
func (this *FS) OpenFileReader(hash string, isPartial bool) (*FileReader, error)
OpenFileReader 打开文件读取器
func (*FS) OpenFileWriter ¶
OpenFileWriter 打开文件写入器
func (*FS) RemoveFile ¶
func (*FS) TestBMap ¶
func (this *FS) TestBMap() map[string]*BlocksFile
type FSOptions ¶
type FSOptions struct { MaxOpenFiles int BytesPerSync int64 SyncTimeout time.Duration MaxSyncFiles int }
func (*FSOptions) EnsureDefaults ¶
func (this *FSOptions) EnsureDefaults()
type FileHeader ¶
type FileHeader struct { Version int `json:"1,omitempty"` ModifiedAt int64 `json:"2,omitempty"` ExpiresAt int64 `json:"3,omitempty"` Status int `json:"4,omitempty"` HeaderSize int64 `json:"5,omitempty"` BodySize int64 `json:"6,omitempty"` ExpiredBodySize int64 `json:"7,omitempty"` HeaderBlocks []BlockInfo `json:"8,omitempty"` BodyBlocks []BlockInfo `json:"9,omitempty"` IsCompleted bool `json:"10,omitempty"` IsWriting bool `json:"11,omitempty"` }
func (*FileHeader) BlockAt ¶
func (this *FileHeader) BlockAt(offset int64) (blockInfo BlockInfo, ok bool)
func (*FileHeader) MaxOffset ¶
func (this *FileHeader) MaxOffset() int64
type FileReader ¶
type FileReader struct {
// contains filtered or unexported fields
}
func NewFileReader ¶
func NewFileReader(bFile *BlocksFile, fp *os.File, fileHeader *FileHeader) *FileReader
func (*FileReader) Close ¶
func (this *FileReader) Close() error
func (*FileReader) FileHeader ¶
func (this *FileReader) FileHeader() *FileHeader
func (*FileReader) Free ¶
func (this *FileReader) Free() error
func (*FileReader) ReadAt ¶
func (this *FileReader) ReadAt(b []byte, offset int64) (n int, err error)
func (*FileReader) Reset ¶
func (this *FileReader) Reset(fileHeader *FileHeader)
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
FileWriter file writer not thread-safe
func NewFileWriter ¶
func NewFileWriter(bFile *BlocksFile, hash string, bodySize int64, isPartial bool) (*FileWriter, error)
func (*FileWriter) Close ¶
func (this *FileWriter) Close() error
func (*FileWriter) Discard ¶
func (this *FileWriter) Discard() error
func (*FileWriter) WriteBodyAt ¶
func (this *FileWriter) WriteBodyAt(b []byte, offset int64) (n int, err error)
func (*FileWriter) WriteHeader ¶
func (this *FileWriter) WriteHeader(b []byte) (n int, err error)
type GzipReaderPool ¶
type GzipReaderPool struct {
// contains filtered or unexported fields
}
func NewGzipReaderPool ¶
func NewGzipReaderPool() *GzipReaderPool
func (*GzipReaderPool) Put ¶
func (this *GzipReaderPool) Put(reader *gzip.Reader)
type GzipWriterPool ¶
type GzipWriterPool struct {
// contains filtered or unexported fields
}
func NewGzipWriterPool ¶
func NewGzipWriterPool() *GzipWriterPool
func (*GzipWriterPool) Put ¶
func (this *GzipWriterPool) Put(writer *gzip.Writer)
type LazyFileHeader ¶
type LazyFileHeader struct {
// contains filtered or unexported fields
}
LazyFileHeader load file header lazily to save memory
func NewLazyFileHeader ¶
func NewLazyFileHeader(fileHeader *FileHeader) *LazyFileHeader
func NewLazyFileHeaderFromData ¶
func NewLazyFileHeaderFromData(rawData []byte) *LazyFileHeader
func (*LazyFileHeader) FileHeaderUnsafe ¶
func (this *LazyFileHeader) FileHeaderUnsafe() (*FileHeader, error)
type MetaAction ¶
type MetaAction = byte
const ( MetaActionNew MetaAction = '+' MetaActionRemove MetaAction = '-' )
func DecodeMetaBlock ¶
func DecodeMetaBlock(blockBytes []byte) (action MetaAction, hash string, data []byte, err error)
type MetaFile ¶
type MetaFile struct {
// contains filtered or unexported fields
}
func (*MetaFile) CloneFileHeader ¶
func (this *MetaFile) CloneFileHeader(hash string) (header *FileHeader, ok bool)
func (*MetaFile) FileHeader ¶
func (this *MetaFile) FileHeader(hash string) (header *FileHeader, ok bool)
func (*MetaFile) FileHeaderUnsafe ¶
func (this *MetaFile) FileHeaderUnsafe(hash string) (header *FileHeader, ok bool)
func (*MetaFile) FileHeaders ¶
func (this *MetaFile) FileHeaders() map[string]*LazyFileHeader
func (*MetaFile) RemoveFile ¶
func (*MetaFile) SyncUnsafe ¶
func (*MetaFile) WriteBodyBlockUnsafe ¶
func (*MetaFile) WriteClose ¶
func (*MetaFile) WriteHeaderBlockUnsafe ¶
Click to show internal directories.
Click to hide internal directories.