| 1 |
# Examples |
| 2 |
|
| 3 |
This folder contains usage examples of the Reed-Solomon encoder. |
| 4 |
|
| 5 |
# Simple Encoder/Decoder |
| 6 |
|
| 7 |
Shows basic use of the encoder, and will encode a single file into a number of |
| 8 |
data and parity shards. This is meant as an example and is not meant for production use |
| 9 |
since there is a number of shortcomings noted below. |
| 10 |
|
| 11 |
To build an executable use: |
| 12 |
|
| 13 |
```bash |
| 14 |
go build simple-decoder.go |
| 15 |
go build simple-encoder.go |
| 16 |
``` |
| 17 |
|
| 18 |
# Streaming API examples |
| 19 |
|
| 20 |
There are streaming examples of the same functionality, which streams data instead of keeping it in memory. |
| 21 |
|
| 22 |
To build the executables use: |
| 23 |
|
| 24 |
```bash |
| 25 |
go build stream-decoder.go |
| 26 |
go build stream-encoder.go |
| 27 |
``` |
| 28 |
|
| 29 |
# Example usage |
| 30 |
|
| 31 |
On Windows, the following command will generate six files `README.md.0` to `README.md.5` |
| 32 |
|
| 33 |
```bash |
| 34 |
.\simple-encoder.exe .\README.md |
| 35 |
``` |
| 36 |
|
| 37 |
Rename `README.md` to `README.md.org`, and delete two of the six generated files. The following |
| 38 |
command will reconstruct `README.md` from the four generated files. |
| 39 |
|
| 40 |
```bash |
| 41 |
.\simple-decoder.exe .\README.md |
| 42 |
``` |
| 43 |
|
| 44 |
Appreciate that the reconstructed file mau have nul padding as explained in the following shortcomings. |
| 45 |
|
| 46 |
|
| 47 |
## Shortcomings |
| 48 |
* If the file size of the input isn't dividable by the number of data shards |
| 49 |
the output will contain extra zeroes |
| 50 |
* If the shard numbers isn't the same for the decoder as in the |
| 51 |
encoder, invalid output will be generated. |
| 52 |
* If values have changed in a shard, it cannot be reconstructed. |
| 53 |
* If two shards have been swapped, reconstruction will always fail. |
| 54 |
You need to supply the shards in the same order as they were given to you. |
| 55 |
|
| 56 |
The solution for this is to save a metadata file containing: |
| 57 |
|
| 58 |
* File size. |
| 59 |
* The number of data/parity shards. |
| 60 |
* HASH of each shard. |
| 61 |
* Order of the shards. |
| 62 |
|
| 63 |
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. |