Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bindings/nodejs): write support string #1520

Merged
merged 1 commit into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bindings/nodejs/__test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('test memory write & read', async (t) => {
let content = "hello world"
let path = 'test'

await op.write(path, Buffer.from(content))
await op.write(path, content)

let meta = await op.stat(path)
t.is(meta.mode, 0)
Expand All @@ -43,7 +43,7 @@ test('test memory write & read synchronously', (t) => {
let content = "hello world"
let path = 'test'

op.writeSync(path, Buffer.from(content))
op.writeSync(path, content)

let meta = op.statSync(path)
t.is(meta.mode, 0)
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,13 @@ impl Operator {
}

#[napi]
pub async fn write(&self, path: String, content: Buffer) -> Result<()> {
pub async fn write(&self, path: String, content: Either<Buffer, String>) -> Result<()> {
Xuanwo marked this conversation as resolved.
Show resolved Hide resolved
let c = content.as_ref().to_owned();
self.0.write(&path, c).await.map_err(format_napi_error)
}

#[napi]
pub fn write_sync(&self, path: String, content: Buffer) -> Result<()> {
pub fn write_sync(&self, path: String, content: Either<Buffer, String>) -> Result<()> {
let c = content.as_ref().to_owned();
self.0.blocking().write(&path, c).map_err(format_napi_error)
}
Expand Down Expand Up @@ -325,7 +325,7 @@ impl Writer {
/// napi will make sure the function is safe, and we didn't do unsafe
/// thing internally.
#[napi]
pub async unsafe fn append(&mut self, content: Buffer) -> Result<()> {
pub async unsafe fn append(&mut self, content: Either<Buffer, String>) -> Result<()> {
let c = content.as_ref().to_owned();
self.0.append(c).await.map_err(format_napi_error)
}
Expand Down