Files
blitz-kt/doc/batched_sequences.md
SuperCraftAlex b3150fd948 io
2024-03-09 20:26:04 +01:00

28 lines
736 B
Markdown

# Batched sequences
## Source
You should make all your sources return `BatchSequence<T>`
and then you can use the `.batched(count: Int)` function
to drastically decrease the amount of single reads in the original source.
Example:
```kt
Path("text.txt") // Path
.getFile() // File
.openRead() // BatchSequence<Byte>
.batched(64) // BatchSequence<Byte>
```
## Sink
You should make all your sinks take `BatchSequence<T>`
and then you can use the `.asBatch()` function to allow
the sink to get multiple bytes at once.
Example:
```kt
val data = myData // Sequence<Byte>
.asBatch() // BatchSequence<Byte>
Path("text.txt") // Path
.getOrCreateFile() // File
.write(data)
```