-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f1732f
commit 6ae208a
Showing
6 changed files
with
111 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,41 @@ | ||
package localstorage | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"path" | ||
) | ||
|
||
func (l *LocalStorage) ReadFile(name string) ([]byte, error) { | ||
return os.ReadFile(path.Join(l.path, name)) | ||
} | ||
|
||
func (l *LocalStorage) OpenFilesFromPos(names []string, pos int64) ([]io.Reader, error) { | ||
readers := []io.Reader{} | ||
for _, name := range names { | ||
file, err := os.Open(path.Join(l.path, name)) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot open file (%s): %s", name, err) | ||
} | ||
defer file.Close() | ||
stat, err := file.Stat() | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot get file stat (%s): %s", name, err) | ||
} | ||
if stat.Size() <= pos { | ||
pos -= stat.Size() | ||
} else { | ||
_, err := file.Seek(pos, 0) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not seek to pos (file: %s): %s", name, err) | ||
} | ||
pos = 0 | ||
readers = append(readers, file) | ||
} | ||
} | ||
if len(readers) == 0 { | ||
return nil, fmt.Errorf("no file contents to read") | ||
} | ||
return readers, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters