Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
mio-19 committed Oct 7, 2024
1 parent 38d7554 commit dae1ba0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion nodejs/src/main/scala/chester/utils/io/impl/DefaultIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import scala.scalajs.js
import scala.scalajs.js.typedarray.Uint8Array
import scala.concurrent.ExecutionContext.Implicits.global
import typings.std.global.fetch
import scala.scalajs.js.typedarray.TypedArrayBuffer

implicit object DefaultIO extends IO[Future] {
type Path = String
Expand All @@ -21,7 +22,13 @@ implicit object DefaultIO extends IO[Future] {

inline override def readString(path: String): Future[String] = fsPromisesMod.readFile(path, BufferEncoding.utf8)

inline override def read(path: String): Future[Array[Byte]] = fsPromisesMod.readFile(path).map(_.toArray)
// TODO: maybe use https://stackoverflow.com/questions/75031248/scala-js-convert-uint8array-to-arraybyte
inline override def read(path: String): Future[Array[Byte]] = for {
buffer <- fsPromisesMod.readFile(path)
b = buffer.asInstanceOf[Uint8Array]
arr = new Array[Short](b.length)
_ = b.copyToArray(arr)
} yield arr.map(_.toByte)

inline override def writeString(path: String, content: String, append: Boolean = false): Future[Unit] = {
if (append) {
Expand Down

0 comments on commit dae1ba0

Please sign in to comment.