blob: ddb43f60428c0fc107aef8794a6b07d4eb55f2e1 [file] [log] [blame]
giolekva1f6577a2020-03-25 12:53:06 +04001package chunk
2
3import (
4 "io"
5 "os"
6
7 "pcloud/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}