Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(README): support new API #4

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ $ go install github.com/oomol-lab/oget
```go
import "github.com/oomol-lab/oget"

_, err := OGet{
_, err := (&OGet{
URL: "https://github.com/oomol-lab/oget/raw/main/tests/target.bin",
FilePath: "/path/to/save/file.bin",
}.Get()
}).Get()

if err != nil {
panic(err)
Expand All @@ -32,15 +32,15 @@ It splits large files into multiple smaller parts for parallel downloading, then
```go
import "github.com/oomol-lab/oget"

_, err := OGet{
_, err := (&OGet{
URL: "https://github.com/oomol-lab/oget/raw/main/tests/target.bin",
// Path to store the final file
FilePath: "/path/to/save/file.bin",
// Number of file parts for splitting and parallel downloading
Parts: 4,
// If not specified, defaults to the same directory as `FilePath`
PartsPath: "/path/to/save/temp/files",
}.Get()
}).Get()

if err != nil {
panic(err)
Expand All @@ -55,7 +55,7 @@ if err != nil {
import "github.com/oomol-lab/oget"

var mux sync.Mutex
_, err := OGet{
_, err := (&OGet{
URL: "https://github.com/oomol-lab/oget/raw/main/tests/target.bin",
FilePath: "/path/to/save/file.bin",
ListenProgress: func(event oget.ProgressEvent) {
Expand All @@ -76,7 +76,7 @@ _, err := OGet{
// Total number of bytes in this step
total := event.Total
},
}.Get()
}).Get()

if err != nil {
panic(err)
Expand All @@ -90,11 +90,11 @@ After downloading, the library performs a SHA512 checksum on the entire file. If
```go
import "github.com/oomol-lab/oget"

_, err := OGet{
_, err := (&OGet{
URL: "https://github.com/oomol-lab/oget/raw/main/tests/target.bin",
FilePath: "/path/to/save/file.bin",
SHA512: "d286fbb1fab9014fdbc543d09f54cb93da6e0f2c809e62ee0c81d69e4bf58eec44571fae192a8da9bc772ce1340a0d51ad638cdba6118909b555a12b005f2930",
}.Get()
}).Get()

if err != nil {
if sha512Error, ok := err.(oget.SHA512Error); ok {
Expand All @@ -113,11 +113,11 @@ import "github.com/oomol-lab/oget"
success := false

for i := 0; i < 10; i++ {
clean, err := OGet{
clean, err := (&OGet{
URL: "https://github.com/oomol-lab/oget/raw/main/tests/target.bin",
FilePath: "/path/to/save/file.bin",
Parts: 4,
}.Get()
}).Get()
if err != nil {
if sha512Error, ok := err.(oget.SHA512Error); ok {
clean()
Expand Down
2 changes: 1 addition & 1 deletion get.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type OGet struct {
ListenProgress ProgressListener
}

func (o OGet) Get() (func() error, error) {
func (o *OGet) Get() (func() error, error) {
clean := func() error { return nil }
task, err := CreateGettingTask(&RemoteFile{
Context: o.Context,
Expand Down
Loading