{"modulePath":"github.com/wavetermdev/waveterm/waveshell","version":"v0.7.6","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package cirfile\n\n## Constants\n\n```go\nconst CurrentVersion = 1\n```\n\n```go\nconst FilePosEmpty = -1 // sentinel, if startpos is set to -1, file is empty\n\n```\n\n```go\nconst FullHeaderFmt = \"%-255s\\n\" // 256 bytes (255 + newline)\n\n```\n\n```go\nconst HeaderFmt1 = \"CBUF%02d %19d %19d %19d %19d\\n\" // 87 bytes\n\n```\nCBUF\\[version] \\[maxsize] \\[fileoffset] \\[startpos] \\[endpos]\n\n```go\nconst HeaderLen = 256 // set to 256 for future expandability\n\n```\n\n```go\nconst InitialLockDelay = 10 * time.Millisecond\n```\n\n```go\nconst InitialLockTries = 5\n```\n\n```go\nconst LockDelay = 100 * time.Millisecond\n```\n\n## Types\n\n```go\ntype File struct {\n\tOSFile       *os.File\n\tVersion      byte\n\tMaxSize      int64\n\tFileOffset   int64\n\tStartPos     int64\n\tEndPos       int64\n\tFileDataSize int64 // size of data (does not include header size)\n\tFlockStatus  int\n}\n```\nFile objects are \\*not\\* multithread safe, operations must be externally synchronized\n\n```go\nfunc CreateCirFile(fileName string, maxSize int64) (*File, error)\n```\nif the file already exists, it is an error. there is a race condition if two goroutines try to create the same file between Stat() and Create(), so\n\n\tthey both might get no error, but only one file will be valid.  if this is a concern, this call\n\tshould be externally synchronized.\n\n```go\nfunc OpenCirFile(fileName string) (*File, error)\n```\ndoes not read metadata because locking could block/fail.  we want to be able to return a valid file struct without blocking.\n\n```go\nfunc (f *File) AppendData(ctx context.Context, buf []byte) error\n```\n\n```go\nfunc (f *File) Close() error\n```\n\n```go\nfunc (f *File) GetStartOffsetAndSize(ctx context.Context) (int64, int64, error)\n```\nreturns (fileOffset, datasize, error) datasize is the current amount of readable data held in the cirfile\n\n```go\nfunc (f *File) ReadAll(ctx context.Context) (int64, []byte, error)\n```\nreturns (offset, data, err)\n\n```go\nfunc (f *File) ReadAtWithMax(ctx context.Context, offset int64, maxSize int64) (int64, []byte, error)\n```\n\n```go\nfunc (f *File) ReadMeta(ctx context.Context) error\n```\n\n```go\nfunc (f *File) ReadNext(ctx context.Context, buf []byte, offset int64) (int64, int, error)\n```\nreturns (realOffset, numread, error) will only return io.EOF when len(data) == 0, otherwise will just do a short read\n\n```go\nfunc (f *File) WriteAt(ctx context.Context, buf []byte, writePos int64) error\n```\ndoes not implement io.WriterAt (needs context)\n\n```go\ntype Stat struct {\n\tLocation   string\n\tVersion    byte\n\tMaxSize    int64\n\tFileOffset int64\n\tDataSize   int64\n}\n```\n\n```go\nfunc StatCirFile(ctx context.Context, fileName string) (*Stat, error)\n```\n\n","path":"github.com/wavetermdev/waveterm/waveshell/pkg/cirfile","name":"cirfile","synopsis":"","isRedistributable":true}
