Skip to content

Commit c2edbe1

Browse files
committed
hasher can be used now as OutputStream
1 parent ef58cec commit c2edbe1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
44

55
## [unreleased]
66
- Switched to Scala.js-1.7.0.
7+
- `hasher` can be used now as `OutputStream`.
78

89
## [2.8.0] - 2021-07-16
910
- Introduced `doneXor`.

shared/src/main/scala/ky/korins/blake3/Hasher.scala

+19-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ package ky.korins.blake3
1212
import java.io.{InputStream, OutputStream}
1313
import java.nio.ByteBuffer
1414

15-
trait Hasher {
15+
trait Hasher extends OutputStream {
1616

1717
/**
1818
* Updates a hasher by provided bytes, returns the same hasher
@@ -224,4 +224,22 @@ trait Hasher {
224224
*/
225225
def doneBase64Url(len: Int): String =
226226
RFC4648.base64_url(done(len))
227+
228+
/**
229+
* Update hash as [[OutputStream]].
230+
*/
231+
override def write(b: Int): Unit =
232+
update(b.toByte)
233+
234+
/**
235+
* Update hash as [[OutputStream]].
236+
*/
237+
override def write(b: Array[Byte]): Unit =
238+
update(b)
239+
240+
/**
241+
* Update hash as [[OutputStream]].
242+
*/
243+
override def write(b: Array[Byte], off: Int, len: Int): Unit =
244+
update(b, off, len)
227245
}

0 commit comments

Comments
 (0)