This is an automated email from the ASF dual-hosted git repository.
suyanhanx pushed a commit to branch nodejs-stream
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/nodejs-stream by this push:
new 015a19312 polish
015a19312 is described below
commit 015a19312958cf5f28e5f5c8d251f347c7797853
Author: suyanhanx <[email protected]>
AuthorDate: Sat Nov 25 15:17:39 2023 +0800
polish
Signed-off-by: suyanhanx <[email protected]>
---
bindings/nodejs/index.js | 16 ++++++++++++----
bindings/nodejs/tests/suites/async.suite.mjs | 4 +++-
bindings/nodejs/tests/suites/sync.suite.mjs | 2 ++
bindings/nodejs/vitest.config.js | 1 +
4 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/bindings/nodejs/index.js b/bindings/nodejs/index.js
index 47ee77957..6c28368fd 100644
--- a/bindings/nodejs/index.js
+++ b/bindings/nodejs/index.js
@@ -28,13 +28,21 @@ class WriterStream extends Writable {
}
_write(chunk, encoding, callback) {
- this.writer.write(chunk)
- callback()
+ try {
+ this.writer.write(chunk)
+ callback()
+ } catch (e) {
+ callback(e)
+ }
}
_final(callback) {
- this.writer.close()
- callback()
+ try {
+ this.writer.close()
+ callback()
+ } catch (e) {
+ callback(e)
+ }
}
}
diff --git a/bindings/nodejs/tests/suites/async.suite.mjs
b/bindings/nodejs/tests/suites/async.suite.mjs
index 40738849a..bcf18919d 100644
--- a/bindings/nodejs/tests/suites/async.suite.mjs
+++ b/bindings/nodejs/tests/suites/async.suite.mjs
@@ -40,7 +40,7 @@ export function run(op) {
const filename = `random_file_${randomUUID()}`
const writer = await op.writer(filename)
- const data = generateFixedBytes(5 * 1024 * 1024)
+ const data = generateFixedBytes(2 * 1024 * 1024)
await writer.write(data)
await writer.write(data)
@@ -48,5 +48,7 @@ export function run(op) {
const stat = await op.stat(filename)
assert.equal(stat.contentLength, data.length * 2)
+
+ await op.delete(filename)
})
}
diff --git a/bindings/nodejs/tests/suites/sync.suite.mjs
b/bindings/nodejs/tests/suites/sync.suite.mjs
index d3dcf966a..774e0e63c 100644
--- a/bindings/nodejs/tests/suites/sync.suite.mjs
+++ b/bindings/nodejs/tests/suites/sync.suite.mjs
@@ -52,6 +52,8 @@ export function run(op) {
const content = op.readSync(filename)
assert.equal(Buffer.compare(content, buf), 0) // 0 means equal
+
+ op.deleteSync(filename)
})
})
}
diff --git a/bindings/nodejs/vitest.config.js b/bindings/nodejs/vitest.config.js
index baaf4bde4..6c38b2dcb 100644
--- a/bindings/nodejs/vitest.config.js
+++ b/bindings/nodejs/vitest.config.js
@@ -28,5 +28,6 @@ export default defineConfig({
environment: 'node',
dir: 'tests',
reporters: 'basic',
+ testTimeout: 300 * 1000,
},
})