blob: 3502a5039ac96d47285154bee139e32e1c722343 [file] [log] [blame]
giolekva892a4e22020-04-27 16:46:22 +04001package chunk
2
3import (
4 "io"
5 "os"
6
7 "github.com/giolekva/pcloud/pfs/api"
8)
9
10type ReadOnlyFileChunk struct {
11 f *os.File
12 offset int
13 size int
14}
15
16func NewReadOnlyFileChunk(f *os.File, offset, size int) Chunk {
17 return &ReadOnlyFileChunk{f, offset, size}
18}
19
20func (c *ReadOnlyFileChunk) Stats() (ChunkInfo, error) {
21 return ChunkInfo{
22 Status: api.ChunkStatus_READY,
23 Size: c.size,
24 Committed: c.size}, nil
25}
26
27func (c *ReadOnlyFileChunk) ReaderAt() io.ReaderAt {
28 return &fileReader{c.f}
29}
30
31func (c *ReadOnlyFileChunk) WriterAt() io.WriterAt {
32 return &fileWriter{c.f}
33}
34
35type fileReader struct {
36 f *os.File
37}
38
39func (f *fileReader) ReadAt(b []byte, offset int64) (int, error) {
40 return f.f.ReadAt(b, offset)
41}
42
43type fileWriter struct {
44 f *os.File
45}
46
47func (f *fileWriter) WriteAt(b []byte, offset int64) (int, error) {
48 return f.f.WriteAt(b, offset)
49}