Skip to content

Commit a05f674

Browse files
committed
Miscellaneous fixes
1 parent ab2a7f0 commit a05f674

20 files changed

+229
-180
lines changed

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import sbt._
55

66
import scala.language.postfixOps
77

8-
val scalaJsIOVersion = "0.3.0.5"
8+
val scalaJsIOVersion = "0.3.0.6"
99
val apiVersion = scalaJsIOVersion
1010
val scalaJsVersion = "2.12.1"
1111

1212
organization := "io.scalajs"
1313

14-
homepage := Some(url("https://github.com/scalajs-io/scalajs.io"))
14+
homepage := Some(url("https://github.com/scalajs-io/nodejs"))
1515

1616
lazy val root = (project in file(".")).
1717
enablePlugins(ScalaJSPlugin).

src/main/scala/io/scalajs/nodejs/crypto/Cipher.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.scalajs.nodejs.crypto
22

33
import io.scalajs.nodejs.buffer.Buffer
4-
import io.scalajs.nodejs.stream.Duplex
4+
import io.scalajs.nodejs.stream.IDuplex
55

66
import scala.scalajs.js
77

@@ -17,7 +17,7 @@ import scala.scalajs.js
1717
* @author lawrence.daniels@gmail.com
1818
*/
1919
@js.native
20-
trait Cipher extends Duplex {
20+
trait Cipher extends IDuplex {
2121

2222
/**
2323
* Returns any remaining enciphered contents. If output_encoding parameter is one of 'binary', 'base64' or 'hex',
@@ -27,7 +27,7 @@ trait Cipher extends Duplex {
2727
* Attempts to call cipher.final() more than once will result in an error being thrown.
2828
* @example cipher.final([output_encoding])
2929
*/
30-
def `final`(output_encoding: String ): String = js.native
30+
def `final`(output_encoding: String): String = js.native
3131

3232
/**
3333
* Returns any remaining enciphered contents. If output_encoding parameter is one of 'binary', 'base64' or 'hex',

src/main/scala/io/scalajs/nodejs/crypto/Decipher.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.scalajs.nodejs.crypto
22

33
import io.scalajs.nodejs.buffer.Buffer
4-
import io.scalajs.nodejs.stream.Duplex
4+
import io.scalajs.nodejs.stream.IDuplex
55

66
import scala.scalajs.js
77

@@ -17,7 +17,7 @@ import scala.scalajs.js
1717
* @author lawrence.daniels@gmail.com
1818
*/
1919
@js.native
20-
trait Decipher extends Duplex {
20+
trait Decipher extends IDuplex {
2121

2222
/**
2323
* Returns any remaining deciphered contents. If output_encoding parameter is one of 'binary', 'base64' or 'hex',

src/main/scala/io/scalajs/nodejs/crypto/Hash.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.scalajs.nodejs.crypto
22

33
import io.scalajs.nodejs.buffer.Buffer
4-
import io.scalajs.nodejs.stream.Duplex
4+
import io.scalajs.nodejs.stream.IDuplex
55

66
import scala.scalajs.js
77

@@ -16,7 +16,7 @@ import scala.scalajs.js
1616
* @author lawrence.daniels@gmail.com
1717
*/
1818
@js.native
19-
trait Hash extends Duplex {
19+
trait Hash extends IDuplex {
2020

2121
/**
2222
* Calculates the digest of all of the data passed to be hashed (using the hash.update() method). The encoding can

src/main/scala/io/scalajs/nodejs/crypto/Hmac.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.scalajs.nodejs.crypto
22

33
import io.scalajs.nodejs.buffer.Buffer
4-
import io.scalajs.nodejs.stream.Duplex
4+
import io.scalajs.nodejs.stream.IDuplex
55

66
import scala.scalajs.js
77

@@ -17,7 +17,7 @@ import scala.scalajs.js
1717
* @author lawrence.daniels@gmail.com
1818
*/
1919
@js.native
20-
trait Hmac extends Duplex {
20+
trait Hmac extends IDuplex {
2121

2222
/**
2323
* Calculates the HMAC digest of all of the data passed using hmac.update(). The encoding can be 'hex', 'binary'

src/main/scala/io/scalajs/nodejs/crypto/Sign.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package io.scalajs.nodejs.crypto
22

33
import io.scalajs.nodejs.buffer.Buffer
4-
import io.scalajs.nodejs.stream
5-
import io.scalajs.nodejs.stream.Duplex
4+
import io.scalajs.nodejs.stream.IDuplex
65

76
import scala.scalajs.js
87

@@ -18,7 +17,7 @@ import scala.scalajs.js
1817
* @author lawrence.daniels@gmail.com
1918
*/
2019
@js.native
21-
trait Sign extends Duplex {
20+
trait Sign extends IDuplex {
2221

2322
def sign(private_key: String): String = js.native
2423

src/main/scala/io/scalajs/nodejs/crypto/Verify.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package io.scalajs.nodejs.crypto
22

33
import io.scalajs.nodejs.buffer.Buffer
4-
import io.scalajs.nodejs.stream
5-
import io.scalajs.nodejs.stream.Duplex
4+
import io.scalajs.nodejs.stream.IDuplex
65

76
import scala.scalajs.js
87

@@ -17,7 +16,7 @@ import scala.scalajs.js
1716
* @author lawrence.daniels@gmail.com
1817
*/
1918
@js.native
20-
trait Verify extends Duplex {
19+
trait Verify extends IDuplex {
2120

2221
/**
2322
* Updates the Verify content with the given data.

src/main/scala/io/scalajs/nodejs/fs/ReadStream.scala

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package io.scalajs.nodejs.fs
22

33
import io.scalajs.nodejs.FileDescriptor
4+
import io.scalajs.nodejs.buffer.Buffer
45
import io.scalajs.nodejs.stream.Readable
6+
import io.scalajs.util.PromiseHelper.promiseCallback1
57

8+
import scala.concurrent.Promise
69
import scala.scalajs.js
10+
import scala.scalajs.js.|
711

812
/**
913
* fs.ReadStream - ReadStream is a Readable Stream.
@@ -12,12 +16,31 @@ import scala.scalajs.js
1216
@js.native
1317
trait ReadStream extends Readable {
1418

19+
/////////////////////////////////////////////////////////////////////////////////
20+
// Properties
21+
/////////////////////////////////////////////////////////////////////////////////
22+
23+
/**
24+
* The number of bytes read so far.
25+
*/
26+
def bytesRead: Double = js.native
27+
1528
/**
1629
* The path to the file the stream is reading from as specified in the first argument to fs.createReadStream().
1730
* If path is passed as a string, then readStream.path will be a string. If path is passed as a Buffer, then
1831
* readStream.path will be a Buffer.
1932
*/
20-
def path: js.Any = js.native
33+
def path: Buffer | String = js.native
34+
35+
/////////////////////////////////////////////////////////////////////////////////
36+
// Methods
37+
/////////////////////////////////////////////////////////////////////////////////
38+
39+
/**
40+
* Undocumented method
41+
* @see https://github.com/nodejs/node-v0.x-archive/blob/cfcb1de130867197cbc9c6012b7e84e08e53d032/lib/fs.js#L1597-L1620
42+
*/
43+
def close[A](callback: js.Function1[Unit, A]): Unit = js.native
2144

2245
}
2346

@@ -33,13 +56,24 @@ object ReadStream {
3356
*/
3457
implicit class ReadStreamExtensions(val stream: ReadStream) extends AnyVal {
3558

59+
@inline
60+
def closeAsync: Promise[Unit] = promiseCallback1[Unit](stream.close)
61+
62+
}
63+
64+
/**
65+
* Read Stream Events
66+
* @author lawrence.daniels@gmail.com
67+
*/
68+
implicit class ReadStreamEvents(val stream: ReadStream) extends AnyVal {
69+
3670
/**
3771
* Emitted when the ReadStream's underlying file descriptor has been closed using the fs.close() method.
3872
* @param listener the event handler
3973
* @since 0.1.93
4074
*/
4175
@inline
42-
def onClose(listener: () => Any): stream.type = stream.on("close", listener)
76+
def onClose[A](listener: () => A): stream.type = stream.on("close", listener)
4377

4478
/**
4579
* Emitted when the ReadStream's file is opened.
@@ -50,7 +84,7 @@ object ReadStream {
5084
* @since 0.1.93
5185
*/
5286
@inline
53-
def onOpen(listener: FileDescriptor => Any): stream.type = stream.on("open", listener)
87+
def onOpen[A](listener: FileDescriptor => A): stream.type = stream.on("open", listener)
5488

5589
}
5690

src/main/scala/io/scalajs/nodejs/fs/WriteStream.scala

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package io.scalajs.nodejs.fs
22

3+
import io.scalajs.util.PromiseHelper._
34
import io.scalajs.nodejs.FileDescriptor
5+
import io.scalajs.nodejs.buffer.Buffer
46
import io.scalajs.nodejs.stream.Writable
57

8+
import scala.concurrent.Promise
69
import scala.scalajs.js
10+
import scala.scalajs.js.|
711

812
/**
913
* fs.WriteStream - WriteStream is a Writable Stream.
@@ -12,6 +16,10 @@ import scala.scalajs.js
1216
@js.native
1317
trait WriteStream extends Writable {
1418

19+
/////////////////////////////////////////////////////////////////////////////////
20+
// Properties
21+
/////////////////////////////////////////////////////////////////////////////////
22+
1523
/**
1624
* The number of bytes written so far. Does not include data that is still queued for writing.
1725
*/
@@ -22,7 +30,17 @@ trait WriteStream extends Writable {
2230
* If path is passed as a string, then writeStream.path will be a string. If path is passed as a Buffer, then
2331
* writeStream.path will be a Buffer.
2432
*/
25-
def path: js.Any = js.native
33+
def path: Buffer | String = js.native
34+
35+
/////////////////////////////////////////////////////////////////////////////////
36+
// Methods
37+
/////////////////////////////////////////////////////////////////////////////////
38+
39+
/**
40+
* Undocumented method
41+
* @see https://github.com/nodejs/node-v0.x-archive/blob/cfcb1de130867197cbc9c6012b7e84e08e53d032/lib/fs.js#L1597-L1620
42+
*/
43+
def close[A](callback: js.Function1[Unit, A]): Unit = js.native
2644

2745
}
2846

@@ -38,12 +56,24 @@ object WriteStream {
3856
*/
3957
implicit class WriteStreamExtensions(val stream: WriteStream) extends AnyVal {
4058

59+
@inline
60+
def closeAsync: Promise[Unit] = promiseCallback1[Unit](stream.close)
61+
62+
}
63+
64+
/**
65+
* Write Stream Events
66+
* @author lawrence.daniels@gmail.com
67+
*/
68+
implicit class WriteStreamEvents(val stream: WriteStream) extends AnyVal {
69+
4170
/**
4271
* Emitted when the WriteStream's underlying file descriptor has been closed using the fs.close() method.
4372
* @param listener the event handler
4473
* @since 0.1.93
4574
*/
46-
@inline def onClose(listener: () => Any) = stream.on("close", listener)
75+
@inline
76+
def onClose[A](listener: () => A): stream.type = stream.on("close", listener)
4777

4878
/**
4979
* Emitted when the WriteStream's file is opened.
@@ -53,7 +83,8 @@ object WriteStream {
5383
* </ul>
5484
* @since 0.1.93
5585
*/
56-
@inline def onOpen(listener: FileDescriptor => Any) = stream.on("open", listener)
86+
@inline
87+
def onOpen[A](listener: FileDescriptor => A): stream.type = stream.on("open", listener)
5788

5889
}
5990

src/main/scala/io/scalajs/nodejs/http/IncomingMessage.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.scalajs.nodejs.http
22

3-
import io.scalajs.nodejs.net.Socket
4-
import io.scalajs.nodejs.stream
53
import io.scalajs.nodejs.net.Socket
64
import io.scalajs.nodejs.stream.Readable
75

@@ -111,10 +109,10 @@ object IncomingMessage {
111109
implicit class IncomingMessageExtensions(val message: IncomingMessage) extends AnyVal {
112110

113111
@inline
114-
def onClose(callback: js.Function) = message.on("close", callback)
112+
def onClose(callback: js.Function): message.type = message.on("close", callback)
115113

116114
@inline
117-
def setTimeout(duration: FiniteDuration, callback: js.Function) =
115+
def setTimeout(duration: FiniteDuration, callback: js.Function): Unit =
118116
message.setTimeout(duration.toMillis.toDouble, callback)
119117

120118
}

src/main/scala/io/scalajs/nodejs/http/ServerResponse.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package io.scalajs.nodejs.http
22

33
import io.scalajs.nodejs.buffer.Buffer
44
import io.scalajs.nodejs.events.IEventEmitter
5-
import io.scalajs.nodejs.stream.Duplex
5+
import io.scalajs.nodejs.stream.IDuplex
66

77
import scala.scalajs.js
88

@@ -12,7 +12,7 @@ import scala.scalajs.js
1212
* @see [[https://nodejs.org/api/http.html#http_class_http_serverresponse]]
1313
*/
1414
@js.native
15-
trait ServerResponse extends IEventEmitter with Duplex {
15+
trait ServerResponse extends IEventEmitter with IDuplex {
1616

1717
/////////////////////////////////////////////////////////////////////////////////
1818
// Properties

src/main/scala/io/scalajs/nodejs/net/Socket.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.scalajs.nodejs.net
22

33
import io.scalajs.RawOptions
4-
import io.scalajs.nodejs.stream.Duplex
4+
import io.scalajs.nodejs.stream.{Duplex, IDuplex}
55

66
import scala.scalajs.js
77
import scala.scalajs.js.annotation.JSImport
@@ -15,7 +15,7 @@ import scala.scalajs.js.|
1515
*/
1616
@js.native
1717
@JSImport("net", "Socket")
18-
class Socket extends Duplex {
18+
class Socket extends IDuplex {
1919

2020
/////////////////////////////////////////////////////////////////////////////////
2121
// Properties

0 commit comments

Comments
 (0)