Skip to content

Commit

Permalink
docs: update reader example and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Jun 13, 2023
1 parent 48cb14d commit a07c6a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,22 @@ Install via `v` cli
- Bar Reader for `io` operations.

```v
// 500 MB of sample content.
content := '1234567890'.repeat(50 * 1024 * 1024)
// Returns an `io.BufferedReader` that displays a progressing bar when used in a reader operation.
pub fn (b Bar) reader(reader io.Reader, size u64) &io.BufferedReader
```

```v
mut src_file := os.open(src_file_path)!
mut dst_file := os.create(dst_file_path)!
mut r := bar_reader(Bar{}, content.bytes())
mut f := os.create('testfile')!
io.cp(mut r, mut f)!
bar := bartender.Bar{}
mut bar_reader := bar.reader(src_file, os.file_size(src_file_path))
io.cp(mut bar_reader, mut dst_file)!
```

### Run examples

Extended and executable examples can be found in the sample files.
Extended and executable examples can be found in the `examples` directory.

```
v run examples/<file>.v
Expand Down
6 changes: 3 additions & 3 deletions examples/reader_smooth.v
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() {
os.rm(file_path) or { panic(err) }
}

// Create reader.
// Create reader
data := [u8(1), 2, 3, 4, 5, 6, 7, 8, 9, `\n`].repeat(5 * 1024 * 1024 / 10) // 5MiB
mut r := io.new_buffered_reader(
reader: MyCustomReader{
Expand All @@ -51,8 +51,8 @@ fn main() {
cap: 8 * 1024 // 8 KiB
)

// Create bar readre based on reader.
// Create a bar reader based on `r` reader
mut bar_reader := b.reader(r, u64(data.len))
// Use bar reader.
// Use `bar_reader`
io.cp(mut bar_reader, mut file)!
}
4 changes: 2 additions & 2 deletions src/lib.v
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub fn (mut b Bar) reset() {
b.reset_()
}

// Returns a `io.BufferedReader` that displays a progressing bar when used in a reader operation.
// Returns an `io.BufferedReader` that displays a progressing bar when used in a reader operation.
pub fn (b Bar) reader(reader io.Reader, size u64) &io.BufferedReader {
return bar_reader(b, reader, size)
}
Expand Down Expand Up @@ -121,7 +121,7 @@ pub fn (mut b SmoothBar) reset() {
b.setup()
}

// Returns a `io.BufferedReader` that displays a progressing bar when used in a reader operation.
// Returns an `io.BufferedReader` that displays a progressing bar when used in a reader operation.
pub fn (b SmoothBar) reader(reader io.Reader, size u64) &io.BufferedReader {
return bar_reader(b, reader, size)
}
Expand Down

0 comments on commit a07c6a1

Please sign in to comment.