Skip to content

Commit

Permalink
adding some doc, and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicalTux committed Jan 13, 2020
1 parent 7663da7 commit 71df8ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (f *File) isComplete() bool {
log.Printf("idle: file is now complete, marking as such")

f.complete = true
f.savePart()
f.savePart()

return true
}
Expand Down
3 changes: 3 additions & 0 deletions part.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"os"
)

// SavePart triggers an immediate save of the download status to a .part file
// on disk, allowing resume to happen if the program terminates and is opened
// again.
func (f *File) SavePart() error {
f.lk.Lock()
defer f.lk.Unlock()
Expand Down
20 changes: 19 additions & 1 deletion read.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"os"
)

func (f *File) getSize() error {
Expand Down Expand Up @@ -67,7 +68,20 @@ func (f *File) GetSize() (int64, error) {
return f.size, nil
}

// Seek in file for next Read() operation.
// Stat() will obtain the information of the underlying file after checking
// its size matches that of the file to download.
func (f *File) Stat() (os.FileInfo, error) {
_, err := f.GetSize()
if err != nil {
return nil, err
}

return f.local.Stat()
}

// Seek in file for next Read() operation. If you use io.SeekEnd but the file
// download hasn't started, a HEAD request will be made to obtain the file's
// size.
func (f *File) Seek(offset int64, whence int) (int64, error) {
f.lk.Lock()
defer f.lk.Unlock()
Expand Down Expand Up @@ -101,6 +115,8 @@ func (f *File) Seek(offset int64, whence int) (int64, error) {
}
}

// Read will read data from the file at the current position after checking
// it was successfully downloaded.
func (f *File) Read(p []byte) (n int, err error) {
// read data
f.lk.Lock()
Expand All @@ -113,6 +129,8 @@ func (f *File) Read(p []byte) (n int, err error) {
return
}

// ReadAt will read data from the disk at a specified offset after checking
// it was successfully downloaded.
func (f *File) ReadAt(p []byte, off int64) (int, error) {
f.lk.Lock()
defer f.lk.Unlock()
Expand Down

0 comments on commit 71df8ef

Please sign in to comment.