You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2023/04/14 08:25:52 UTC
[incubator-opendal] 01/01: ci: Fix format after adding editorconfig
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch fix-format
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit 97f9a4b3568062804e8143a592e3647041631ace
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Fri Apr 14 16:25:28 2023 +0800
ci: Fix format after adding editorconfig
Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
.editorconfig | 3 +
bindings/nodejs/README.md | 16 ++---
bindings/nodejs/benchmark/README.md | 10 +--
bindings/nodejs/benchmark/deno.ts | 138 ++++++++++++++++++------------------
bindings/nodejs/benchmark/node.js | 126 ++++++++++++++++----------------
bindings/nodejs/scripts/header.js | 10 +--
bindings/nodejs/tests/binding.js | 36 +++++-----
7 files changed, 171 insertions(+), 168 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index 64b242b8..81a44636 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -36,3 +36,6 @@ trim_trailing_whitespace = false
[*.yml]
indent_size = 2
+
+[*.json]
+indent_size = 2
diff --git a/bindings/nodejs/README.md b/bindings/nodejs/README.md
index f57fe91c..07818d64 100644
--- a/bindings/nodejs/README.md
+++ b/bindings/nodejs/README.md
@@ -18,12 +18,12 @@ See our documentations on [opendal.apache.org](https://opendal.apache.org/docs/n
import { Operator } from "opendal";
async function main() {
- const op = new Operator("fs", { root: "/tmp" });
- await op.write("test", "Hello, World!");
- const bs = await op.read("test");
- console.log(new TextDecoder().decode(bs));
- const meta = await op.stat("test");
- console.log(`contentLength: ${meta.contentLength}`);
+ const op = new Operator("fs", { root: "/tmp" });
+ await op.write("test", "Hello, World!");
+ const bs = await op.read("test");
+ console.log(new TextDecoder().decode(bs));
+ const meta = await op.stat("test");
+ console.log(`contentLength: ${meta.contentLength}`);
}
main();
@@ -31,8 +31,8 @@ main();
## Contributing
-- Install latest `Rust`
-- Install `Node.js@10+` which fully supported `Node-API`
+- Install latest `Rust`
+- Install `Node.js@10+` which fully supported `Node-API`
We are using `corepack` to specific package manager:
diff --git a/bindings/nodejs/benchmark/README.md b/bindings/nodejs/benchmark/README.md
index 9be0a942..fcca80c2 100644
--- a/bindings/nodejs/benchmark/README.md
+++ b/bindings/nodejs/benchmark/README.md
@@ -4,11 +4,11 @@ This benchmark is test against the opendal and aws js sdk.
To run the benchmark, please make sure the following env have been set correctly.
-- AWS_S3_ENDPOINT: the endpoint of the s3 service
-- AWS_S3_REGION: the region of the s3 service
-- AWS_ACCESS_KEY_ID: the access key of the s3 service
-- AWS_SECRET_ACCESS_KEY: the secret key of the s3 service
-- AWS_BUCKET: the bucket name of the s3 service
+- AWS_S3_ENDPOINT: the endpoint of the s3 service
+- AWS_S3_REGION: the region of the s3 service
+- AWS_ACCESS_KEY_ID: the access key of the s3 service
+- AWS_SECRET_ACCESS_KEY: the secret key of the s3 service
+- AWS_BUCKET: the bucket name of the s3 service
To run the benchmark:
diff --git a/bindings/nodejs/benchmark/deno.ts b/bindings/nodejs/benchmark/deno.ts
index f14f167a..aabae40c 100644
--- a/bindings/nodejs/benchmark/deno.ts
+++ b/bindings/nodejs/benchmark/deno.ts
@@ -28,88 +28,88 @@ const hostname = url.hostname
const bucket = Deno.env.get('AWS_BUCKET') || 'benchmark'
const s3 = new S3Client({
- endPoint: hostname,
- useSSL: false,
- port: port,
- region: Deno.env.get('AWS_REGION') || 'us-east-1',
- bucket,
- accessKey: Deno.env.get('AWS_ACCESS_KEY_ID'),
- secretKey: Deno.env.get('AWS_SECRET_ACCESS_KEY'),
+ endPoint: hostname,
+ useSSL: false,
+ port: port,
+ region: Deno.env.get('AWS_REGION') || 'us-east-1',
+ bucket,
+ accessKey: Deno.env.get('AWS_ACCESS_KEY_ID'),
+ secretKey: Deno.env.get('AWS_SECRET_ACCESS_KEY'),
})
const opendal = new Operator('s3', {
- root: '/',
- bucket,
- endpoint,
+ root: '/',
+ bucket,
+ endpoint,
})
const files = [
- {
- name: '4kb',
- file: new Uint8Array(4 * 1024),
- },
- {
- name: '256kb',
- file: new Uint8Array(256 * 1024),
- },
- {
- name: '4mb',
- file: new Uint8Array(4 * 1024 * 1024),
- },
- {
- name: '16mb',
- file: new Uint8Array(16 * 1024 * 1024),
- },
-]
-
-const textDecoder = new TextDecoder()
-const filenams = await Promise.all(
- files.map(async (data) => {
- const filename = `${crypto.randomUUID()}-${data.name}-read-bench`
- await s3.putObject(filename, textDecoder.decode(data.file))
- return filename
- }),
-)
-files.map((data, i) => {
- Deno.bench(
- `opendal: read ${data.name}`,
{
- group: `read ${data.name}`,
+ name: '4kb',
+ file: new Uint8Array(4 * 1024),
},
- async () => {
- await opendal.read(filenams[i])
+ {
+ name: '256kb',
+ file: new Uint8Array(256 * 1024),
},
- )
- Deno.bench(
- `s3: read ${data.name}`,
{
- group: `read ${data.name}`,
+ name: '4mb',
+ file: new Uint8Array(4 * 1024 * 1024),
},
- async () => {
- await s3.getObject(filenams[i])
+ {
+ name: '16mb',
+ file: new Uint8Array(16 * 1024 * 1024),
},
- )
+]
+
+const textDecoder = new TextDecoder()
+const filenams = await Promise.all(
+ files.map(async (data) => {
+ const filename = `${crypto.randomUUID()}-${data.name}-read-bench`
+ await s3.putObject(filename, textDecoder.decode(data.file))
+ return filename
+ }),
+)
+files.map((data, i) => {
+ Deno.bench(
+ `opendal: read ${data.name}`,
+ {
+ group: `read ${data.name}`,
+ },
+ async () => {
+ await opendal.read(filenams[i])
+ },
+ )
+ Deno.bench(
+ `s3: read ${data.name}`,
+ {
+ group: `read ${data.name}`,
+ },
+ async () => {
+ await s3.getObject(filenams[i])
+ },
+ )
})
files.map((data) => {
- Deno.bench(
- `s3: write ${data.name}`,
- {
- group: `write ${data.name}`,
- },
- async () => {
- const filename = `${crypto.randomUUID()}-${data.name}}-s3`
- await s3.putObject(filename, textDecoder.decode(data.file))
- },
- )
- Deno.bench(
- `opendal: write ${data.name}`,
- {
- group: `write ${data.name}`,
- },
- async () => {
- const filename = `${crypto.randomUUID()}-${data.name}}-opendal`
- await opendal.write(filename, textDecoder.decode(data.file))
- },
- )
+ Deno.bench(
+ `s3: write ${data.name}`,
+ {
+ group: `write ${data.name}`,
+ },
+ async () => {
+ const filename = `${crypto.randomUUID()}-${data.name}}-s3`
+ await s3.putObject(filename, textDecoder.decode(data.file))
+ },
+ )
+ Deno.bench(
+ `opendal: write ${data.name}`,
+ {
+ group: `write ${data.name}`,
+ },
+ async () => {
+ const filename = `${crypto.randomUUID()}-${data.name}}-opendal`
+ await opendal.write(filename, textDecoder.decode(data.file))
+ },
+ )
})
diff --git a/bindings/nodejs/benchmark/node.js b/bindings/nodejs/benchmark/node.js
index ff90cbd9..488df823 100644
--- a/bindings/nodejs/benchmark/node.js
+++ b/bindings/nodejs/benchmark/node.js
@@ -29,86 +29,86 @@ const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY
const bucket = process.env.AWS_BUCKET
const opendalClient = new Operator('s3', {
- root: '/',
- bucket,
- endpoint,
+ root: '/',
+ bucket,
+ endpoint,
})
const s3Client = new S3Client({
- endpoint,
- region,
- credentials: {
- accessKeyId,
- secretAccessKey,
- },
+ endpoint,
+ region,
+ credentials: {
+ accessKeyId,
+ secretAccessKey,
+ },
})
const testCases = [
- { name: '4kb', content: Buffer.alloc(4 * 1024, 'opendal', 'utf8') },
- { name: '256kb', content: Buffer.alloc(256 * 1024, 'opendal', 'utf8') },
- { name: '4mb', content: Buffer.alloc(4 * 1024 * 1024, 'opendal', 'utf8') },
- { name: '16mb', content: Buffer.alloc(16 * 1024 * 1024, 'opendal', 'utf8') },
+ { name: '4kb', content: Buffer.alloc(4 * 1024, 'opendal', 'utf8') },
+ { name: '256kb', content: Buffer.alloc(256 * 1024, 'opendal', 'utf8') },
+ { name: '4mb', content: Buffer.alloc(4 * 1024 * 1024, 'opendal', 'utf8') },
+ { name: '16mb', content: Buffer.alloc(16 * 1024 * 1024, 'opendal', 'utf8') },
]
async function benchRead() {
- const uuid = crypto.randomUUID()
- await testCases
- .map((v) => async () => {
- const filename = `${uuid}_${v.name}_read_bench.txt`
- await opendalClient.write(filename, v.content)
+ const uuid = crypto.randomUUID()
+ await testCases
+ .map((v) => async () => {
+ const filename = `${uuid}_${v.name}_read_bench.txt`
+ await opendalClient.write(filename, v.content)
- return suite(
- `read (${v.name})`,
- add(`opendal read (${v.name})`, async () => {
- await opendalClient.read(filename).then((v) => v.toString('utf-8'))
- }),
- add(`s3 read (${v.name})`, async () => {
- const command = new GetObjectCommand({
- Key: filename,
- Bucket: bucket,
- })
- await s3Client.send(command).then((v) => v.Body.transformToString('utf-8'))
- }),
- cycle(),
- complete(),
- )
- })
- .reduce((p, v) => p.then(() => v()), Promise.resolve())
+ return suite(
+ `read (${v.name})`,
+ add(`opendal read (${v.name})`, async () => {
+ await opendalClient.read(filename).then((v) => v.toString('utf-8'))
+ }),
+ add(`s3 read (${v.name})`, async () => {
+ const command = new GetObjectCommand({
+ Key: filename,
+ Bucket: bucket,
+ })
+ await s3Client.send(command).then((v) => v.Body.transformToString('utf-8'))
+ }),
+ cycle(),
+ complete(),
+ )
+ })
+ .reduce((p, v) => p.then(() => v()), Promise.resolve())
}
async function benchWrite() {
- const uuid = crypto.randomUUID()
- await testCases
- .map(
- (v) => () =>
- suite(
- `write (${v.name})`,
- add(`opendal write (${v.name})`, async () => {
- let count = 0
- return async () => opendalClient.write(`${uuid}_${count++}_${v.name}_opendal.txt`, v.content)
- }),
- add(`s3 write (${v.name})`, async () => {
- let count = 0
+ const uuid = crypto.randomUUID()
+ await testCases
+ .map(
+ (v) => () =>
+ suite(
+ `write (${v.name})`,
+ add(`opendal write (${v.name})`, async () => {
+ let count = 0
+ return async () => opendalClient.write(`${uuid}_${count++}_${v.name}_opendal.txt`, v.content)
+ }),
+ add(`s3 write (${v.name})`, async () => {
+ let count = 0
- return async () => {
- const command = new PutObjectCommand({
- Bucket: bucket,
- Key: `${uuid}_${count++}_${v.name}_s3.txt`,
- Body: v.content,
- })
- await s3Client.send(command)
- }
- }),
- cycle(),
- complete(),
- ),
- )
- .reduce((p, v) => p.then(() => v()), Promise.resolve())
+ return async () => {
+ const command = new PutObjectCommand({
+ Bucket: bucket,
+ Key: `${uuid}_${count++}_${v.name}_s3.txt`,
+ Body: v.content,
+ })
+ await s3Client.send(command)
+ }
+ }),
+ cycle(),
+ complete(),
+ ),
+ )
+ .reduce((p, v) => p.then(() => v()), Promise.resolve())
}
async function bench() {
- await benchRead()
- await benchWrite()
+ await benchRead()
+ await benchWrite()
}
bench()
diff --git a/bindings/nodejs/scripts/header.js b/bindings/nodejs/scripts/header.js
index fd10f52b..e5dc51b0 100644
--- a/bindings/nodejs/scripts/header.js
+++ b/bindings/nodejs/scripts/header.js
@@ -22,10 +22,10 @@ const fs = require('fs')
let files = ['generated.js', 'index.d.ts']
for (path of files) {
- let data = fs.readFileSync(path, 'utf8')
- fs.writeFileSync(
- path,
- `/*
+ let data = fs.readFileSync(path, 'utf8')
+ fs.writeFileSync(
+ path,
+ `/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -45,5 +45,5 @@ for (path of files) {
*/
` + data,
- )
+ )
}
diff --git a/bindings/nodejs/tests/binding.js b/bindings/nodejs/tests/binding.js
index dd1e40d2..94ae63bd 100644
--- a/bindings/nodejs/tests/binding.js
+++ b/bindings/nodejs/tests/binding.js
@@ -22,55 +22,55 @@ const { Operator } = require('../index.js')
const { Given, When, Then } = require('@cucumber/cucumber')
Given('A new OpenDAL Blocking Operator', function () {
- this.op = new Operator('memory')
+ this.op = new Operator('memory')
})
When('Blocking write path {string} with content {string}', function (path, content) {
- this.op.writeSync(path, content)
+ this.op.writeSync(path, content)
})
Then('The blocking file {string} should exist', function (path) {
- this.op.statSync(path)
+ this.op.statSync(path)
})
Then('The blocking file {string} entry mode must be file', function (path) {
- let meta = this.op.statSync(path)
- assert(meta.isFile())
+ let meta = this.op.statSync(path)
+ assert(meta.isFile())
})
Then('The blocking file {string} content length must be {int}', function (path, size) {
- let meta = this.op.statSync(path)
- assert(meta.contentLength == size)
+ let meta = this.op.statSync(path)
+ assert(meta.contentLength == size)
})
Then('The blocking file {string} must have content {string}', function (path, content) {
- let bs = this.op.readSync(path)
- assert(bs.toString() == content)
+ let bs = this.op.readSync(path)
+ assert(bs.toString() == content)
})
Given('A new OpenDAL Async Operator', function () {
- this.op = new Operator('memory')
+ this.op = new Operator('memory')
})
When('Async write path {string} with content {string}', async function (path, content) {
- await this.op.write(path, content)
+ await this.op.write(path, content)
})
Then('The async file {string} should exist', async function (path) {
- await this.op.stat(path)
+ await this.op.stat(path)
})
Then('The async file {string} entry mode must be file', async function (path) {
- let meta = await this.op.stat(path)
- assert(meta.isFile())
+ let meta = await this.op.stat(path)
+ assert(meta.isFile())
})
Then('The async file {string} content length must be {int}', async function (path, size) {
- let meta = await this.op.stat(path)
- assert(meta.contentLength == size)
+ let meta = await this.op.stat(path)
+ assert(meta.contentLength == size)
})
Then('The async file {string} must have content {string}', async function (path, content) {
- let bs = await this.op.read(path)
- assert(bs.toString() == content)
+ let bs = await this.op.read(path)
+ assert(bs.toString() == content)
})