Skip to content

Commit ede83ca

Browse files
committed
Added writeAsync(...) methods to provide promise support
1 parent b1b5491 commit ede83ca

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,9 +1069,9 @@ trait Fs extends IEventEmitter {
10691069
**/
10701070
def write(fd: FileDescriptor,
10711071
buffer: Buffer | Uint8Array,
1072-
offset: Int = js.native,
1073-
length: Int = js.native,
1074-
position: Int = js.native,
1072+
offset: Integer = js.native,
1073+
length: Integer = js.native,
1074+
position: Integer = js.native,
10751075
callback: FsCallback2[Int, Buffer]): Unit = js.native
10761076

10771077
/**

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.scalajs.util.PromiseHelper._
55

66
import scala.concurrent.Promise
77
import scala.scalajs.js
8+
import scala.scalajs.js.typedarray.Uint8Array
89
import scala.scalajs.js.|
910

1011
/**
@@ -124,6 +125,27 @@ package object fs {
124125
def watchAsync(filename: String, options: FSWatcherOptions = null): Promise[(String, String)] =
125126
promiseCallback2[String, String](fs.watch(filename, options, _))
126127

128+
@inline
129+
def writeAsync(fd: FileDescriptor,
130+
buffer: Buffer | Uint8Array,
131+
offset: Integer = null,
132+
length: Integer = null,
133+
position: Integer = null): Promise[(FileType, Buffer)] = {
134+
promiseWithError2[FileIOError, Int, Buffer](fs.write(fd, buffer, offset, length, position, _))
135+
}
136+
137+
@inline
138+
def writeAsync(fd: FileDescriptor, string: String, position: Int, encoding: String): Promise[(FileType, String)] =
139+
promiseWithError2[FileIOError, Int, String](fs.write(fd, string, position, encoding, _))
140+
141+
@inline
142+
def writeAsync(fd: FileDescriptor, string: String, position: Int): Promise[(FileType, String)] =
143+
promiseWithError2[FileIOError, Int, String](fs.write(fd, string, position, null, _))
144+
145+
@inline
146+
def writeAsync(fd: FileDescriptor, string: String): Promise[(FileType, String)] =
147+
promiseWithError2[FileIOError, Int, String](fs.write(fd, string, _))
148+
127149
@inline
128150
def writeFileAsync(file: String, data: Buffer | String, options: FileOutputOptions = null): Promise[Unit] =
129151
promiseWithError0[FileIOError](fs.writeFile(file, data, options, _))

0 commit comments

Comments
 (0)