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

Added example usage to example/README.md; fixed some typos #269

Merged
merged 1 commit into from
Jan 26, 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
typos
  • Loading branch information
HJLebbink committed Jan 23, 2024
commit 28ca525999056b35e591e9f0a76a5a08b824bfc2
26 changes: 22 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This folder contains usage examples of the Reed-Solomon encoder.

Shows basic use of the encoder, and will encode a single file into a number of
data and parity shards. This is meant as an example and is not meant for production use
since there is a number of shotcomings noted below.
since there is a number of shortcomings noted below.

To build an executable use:

Expand All @@ -15,7 +15,7 @@ go build simple-decoder.go
go build simple-encoder.go
```

# Streamin API examples
# Streaming API examples

There are streaming examples of the same functionality, which streams data instead of keeping it in memory.

Expand All @@ -26,8 +26,26 @@ go build stream-decoder.go
go build stream-encoder.go
```

# Example usage

On Windows, the following command will generate six files `README.md.0` to `README.md.5`

```bash
.\simple-encoder.exe .\README.md
```

Rename `README.md` to `README.md.org`, and delete two of the six generated files. The following
command will reconstruct `README.md` from the four generated files.

```bash
.\simple-decoder.exe .\README.md
```

Appreciate that the reconstructed file mau have nul padding as explained in the following shortcomings.


## Shortcomings
* If the file size of the input isn't diviable by the number of data shards
* If the file size of the input isn't dividable by the number of data shards
the output will contain extra zeroes
* If the shard numbers isn't the same for the decoder as in the
encoder, invalid output will be generated.
Expand All @@ -42,4 +60,4 @@ The solution for this is to save a metadata file containing:
* HASH of each shard.
* Order of the shards.

If you save these properties, you should abe able to detect file corruption in a shard and be able to reconstruct your data if you have the needed number of shards left.
If you save these properties, you should abe able to detect file corruption in a shard and be able to reconstruct your data if you have the needed number of shards left.
3 changes: 1 addition & 2 deletions examples/simple-decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"

"github.com/klauspost/reedsolomon"
Expand Down Expand Up @@ -77,7 +76,7 @@ func main() {
for i := range shards {
infn := fmt.Sprintf("%s.%d", fname, i)
fmt.Println("Opening", infn)
shards[i], err = ioutil.ReadFile(infn)
shards[i], err = os.ReadFile(infn)
if err != nil {
fmt.Println("Error reading file", err)
shards[i] = nil
Expand Down
2 changes: 1 addition & 1 deletion examples/simple-encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
// Simple encoder example
//
// The encoder encodes a simgle file into a number of shards
// The encoder encodes a simple file into a number of shards
// To reverse the process see "simpledecoder.go"
//
// To build an executable use:
Expand Down
Loading