Skip to content

Commit

Permalink
docs: add details about is binary functions
Browse files Browse the repository at this point in the history
  • Loading branch information
shelepuginivan committed Aug 6, 2024
1 parent 108a373 commit c856811
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,29 @@ go get github.com/shelepuginivan/fsutil

## Documentation

Is available on [pkg.go.dev](https://pkg.go.dev/github.com/shelepuginivan/fsutil)
Is available on [pkg.go.dev](https://pkg.go.dev/github.com/shelepuginivan/fsutil).

## Details about `IsBinary`, `IsBinarySlow` and `IsBinaryFast`

> [!NOTE]
> Available since `v0.2.0`.
Each `IsBinary`, `IsBinarySlow` and `IsBinaryFast` report whether data is
binary, i.e. a non human-readable text, such as image, audio or video stream.

- `IsBinarySlow` has the **best accuracy** and the **worst speed**, since it
checks the entire byte sequence.
- `IsBinaryFast` has the **worst accuracy** and the **best speed** since it
checks only first line of the sequence.
- `IsBinary` is in the middle — it checks the first and every 2^N line
(i.e. 0, 1, 2, 4, 8, 16, etc.), providing a good accuracy while keeping good
performance.

The table below shows the accuracy of these functions, determined by testing
against random byte sequences:

| Function | Mimimal accuracy | Actual accuracy |
| :------------: | :------------------: | :------------------: |
| `IsBinary` | 990/1000 (`99.0%`) | 1000/1000 (`100.0%`) |
| `IsBinarySlow` | 1000/1000 (`100.0%`) | 1000/1000 (`100.0%`) |
| `IsBinaryFast` | 950/1000 (`95.0%`) | 991/1000 (`99.1%`) |

0 comments on commit c856811

Please sign in to comment.