https://github.com/octu0/runlength
a simple run-length algorithm implementation
https://github.com/octu0/runlength
compression-algorithm golang runlength
Last synced: 8 months ago
JSON representation
a simple run-length algorithm implementation
- Host: GitHub
- URL: https://github.com/octu0/runlength
- Owner: octu0
- License: mit
- Created: 2023-03-12T11:28:04.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-12T11:28:39.000Z (over 3 years ago)
- Last Synced: 2024-12-30T03:43:17.820Z (over 1 year ago)
- Topics: compression-algorithm, golang, runlength
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `runlength`
a simple run-length algorithm implementation.
### Example Encode
```go
package main
import (
"bytes"
"github.com/octu0/runlength"
)
func main() {
out := bytes.NewBuffer(nil)
input := []byte{1, 1, 1, 1, 1, 2, 2, 2, 3, 4, 5, 5, 5, 5}
enc := runlength.NewEncoder(out)
if err := enc.Encode(input); err != nil {
panic(err)
}
println(out.Bytes()) // => [5 1 3 2 1 3 1 4 4 5]
}
```
### Example Decode
```go
package main
import (
"bytes"
"github.com/octu0/runlength"
)
func main() {
out := bytes.NewBuffer(nil)
input := []byte{5, 1, 3, 2, 1, 3, 1, 4, 4, 5}
dec := runlength.NewDecoder(bytes.NewReader(input))
if err := dec.Decode(output); err != nil {
panic(err)
}
println(out.Bytes()) // => [1 1 1 1 1 2 2 2 3 4 5 5 5 5]
}
```
# License
MIT, see LICENSE file for details.