-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cross build fs2.io for Scala.js (#2453)
* Extract JVM-specific io implementation * Add Node.js types dependency * Move resources to JVM directory * Fix build * Implement FileHandle for JS * Fix scala 3 compile errors * Formatting * Disable fail-fast CI * Regenerate workflow * Trigger CI * Implement Socket for Node.js * Formatting * Fix 2.12 compile * Renaming * More socket implementing * Renaming * Implement UDP for Node * Debugging, tcp now passing tests :) * Formatting * Improve ScalablyTyped build * Uncomment forgotten line * UdpSuite passing on Node.js * Formatting * Bump ST plugin. Scala 3 support! * Revert "Disable fail-fast CI" This reverts commit baa0f52. * Regenerate workflow * Fix scala 3 compile * Refactoring * TLS on Node.js * Delete duplicated resource * Fix scala 3 compile * Update yarn.lock * Add JS methods to Chunk[Byte] * Make ST facade internal, new public APIs * Formatting * Polish SecureContext API * Polish TLSParameters API * Fix Scala 2.12 compile * Fixup TLS suite * Refactor UnixSockets * Fix scala 3 compile * Annotate/simplify MiMa exclusions
- Loading branch information
1 parent
b119f82
commit 670be35
Showing
101 changed files
with
7,104 additions
and
565 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2013 Functional Streams for Scala | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package fs2 | ||
|
||
import scala.scalajs.js.typedarray.ArrayBuffer | ||
import scala.scalajs.js.typedarray.TypedArrayBuffer | ||
import scala.scalajs.js.typedarray.Uint8Array | ||
import scala.scalajs.js.typedarray.TypedArrayBufferOps._ | ||
|
||
trait ChunkRuntimePlatform[+O] { self: Chunk[O] => | ||
|
||
def toJSArrayBuffer[B >: O](implicit ev: B =:= Byte): ArrayBuffer = { | ||
val bb = toByteBuffer[B] | ||
if (bb.hasArrayBuffer()) | ||
bb.arrayBuffer() | ||
else { | ||
val ab = new ArrayBuffer(bb.remaining()) | ||
TypedArrayBuffer.wrap(ab).put(bb) | ||
ab | ||
} | ||
} | ||
|
||
def toUint8Array[B >: O](implicit ev: B =:= Byte): Uint8Array = { | ||
val ab = toJSArrayBuffer[B] | ||
new Uint8Array(ab, 0, ab.byteLength) | ||
} | ||
|
||
} | ||
|
||
trait ChunkCompanionRuntimePlatform { self: Chunk.type => | ||
|
||
def jsArrayBuffer(buffer: ArrayBuffer): Chunk[Byte] = | ||
byteBuffer(TypedArrayBuffer.wrap(buffer)) | ||
|
||
def uint8Array(array: Uint8Array): Chunk[Byte] = | ||
jsArrayBuffer(array.buffer) | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
core/js/src/test/scala/fs2/ChunkRuntimePlatformSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2013 Functional Streams for Scala | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package fs2 | ||
|
||
import org.scalacheck.Arbitrary | ||
import org.scalacheck.Gen | ||
import org.scalacheck.Prop.forAll | ||
|
||
class ChunkRuntimePlatformSuite extends Fs2Suite { | ||
override def scalaCheckTestParameters = | ||
super.scalaCheckTestParameters | ||
.withMinSuccessfulTests(if (isJVM) 100 else 25) | ||
.withWorkers(1) | ||
|
||
// Override to remove from implicit scope | ||
override val byteChunkArbitrary = Arbitrary(???) | ||
|
||
def testByteChunk( | ||
genChunk: Gen[Chunk[Byte]], | ||
name: String | ||
): Unit = | ||
group(s"$name") { | ||
implicit val implicitChunkArb: Arbitrary[Chunk[Byte]] = Arbitrary(genChunk) | ||
property("JSArrayBuffer conversion is idempotent") { | ||
forAll { (c: Chunk[Byte]) => | ||
assertEquals(Chunk.jsArrayBuffer(c.toJSArrayBuffer), c) | ||
} | ||
} | ||
property("Uint8Array conversion is idempotent") { | ||
forAll { (c: Chunk[Byte]) => | ||
assertEquals(Chunk.uint8Array(c.toUint8Array), c) | ||
} | ||
} | ||
} | ||
|
||
testByteChunk(byteBufferChunkGenerator, "ByteBuffer") | ||
testByteChunk(byteVectorChunkGenerator, "ByteVector") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) 2013 Functional Streams for Scala | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package fs2 | ||
|
||
trait ChunkRuntimePlatform[+O] | ||
|
||
trait ChunkCompanionRuntimePlatform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2013 Functional Streams for Scala | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package fs2 | ||
package io | ||
package file | ||
|
||
import fs2.internal.jsdeps.node.fsPromisesMod | ||
import cats.effect.kernel.Async | ||
import cats.syntax.all._ | ||
import scala.scalajs.js.typedarray.ArrayBuffer | ||
import scala.scalajs.js.typedarray.TypedArrayBuffer | ||
import scala.scalajs.js.typedarray.TypedArrayBufferOps._ | ||
|
||
private[file] trait FileHandlePlatform[F[_]] | ||
|
||
private[file] trait FileHandleCompanionPlatform { | ||
private[file] def make[F[_]]( | ||
fd: fsPromisesMod.FileHandle | ||
)(implicit F: Async[F]): FileHandle[F] = | ||
new FileHandle[F] { | ||
|
||
override def force(metaData: Boolean): F[Unit] = | ||
F.fromPromise(F.delay(fsPromisesMod.fdatasync(fd))) | ||
|
||
override def read(numBytes: Int, offset: Long): F[Option[Chunk[Byte]]] = | ||
F.fromPromise(F.delay(fd.read(new ArrayBuffer(numBytes), offset.toDouble, numBytes))).map { | ||
res => | ||
if (res.bytesRead < 0) None | ||
else if (res.bytesRead == 0) Some(Chunk.empty) | ||
else | ||
Some(Chunk.byteBuffer(TypedArrayBuffer.wrap(res.buffer).limit(res.bytesRead.toInt))) | ||
} | ||
|
||
override def size: F[Long] = | ||
F.fromPromise(F.delay(fd.stat())).map(_.size.toLong) | ||
|
||
override def truncate(size: Long): F[Unit] = | ||
F.fromPromise(F.delay(fd.truncate(size.toDouble))) | ||
|
||
override def write(bytes: Chunk[Byte], offset: Long): F[Int] = | ||
F.fromPromise(F.delay(fd.write(bytes.toByteBuffer.arrayBuffer(), offset.toDouble))) | ||
.map(_.bytesWritten.toInt) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2013 Functional Streams for Scala | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package fs2 | ||
package io.file | ||
|
||
import fs2.internal.jsdeps.node.fsMod.PathLike | ||
import fs2.io.internal.ByteChunkOps._ | ||
|
||
sealed abstract class Path { | ||
private[file] def toPathLike: PathLike | ||
} | ||
|
||
object Path { | ||
|
||
def apply(path: String): Path = StringPath(path) | ||
def apply(path: Chunk[Byte]): Path = BufferPath(path) | ||
|
||
private final case class StringPath(path: String) extends Path { | ||
override private[file] def toPathLike: PathLike = path.asInstanceOf[PathLike] | ||
} | ||
|
||
private final case class BufferPath(path: Chunk[Byte]) extends Path { | ||
override private[file] def toPathLike: PathLike = path.toBuffer.asInstanceOf[PathLike] | ||
} | ||
|
||
} |
Oops, something went wrong.