-
Notifications
You must be signed in to change notification settings - Fork 485
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(nodejs): add WriteOptions
for write methods
#4785
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
Cool. I think this code snippet satisfied my needs. |
This comment was marked as outdated.
This comment was marked as outdated.
remove await operator.write(filename, c, {
contentType,
contentDisposition,
})
// or
const writer = await operator.writer(filename, {
contentType,
contentDisposition,
})
// or
operator.writeSync(filename, c, {
contentType,
contentDisposition,
})
// or
const writer = operator.writerSync(filename, {
contentType,
contentDisposition,
}) |
writeWith
methodOpWriteOptions
for write methods
hi, @suyanhanx , should I manually update the |
Please add those new features into upgrade.md as unreleased. That's enough. We will update the version when we release it. |
Thanks replied, I will add it lately |
This is not something you need to finish in this PR.😊A seperate PR is okay. |
bindings/nodejs/generated.d.ts
Outdated
@@ -32,6 +32,35 @@ export interface ListOptions { | |||
limit?: number | |||
recursive?: boolean | |||
} | |||
export interface OpWriteOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for you effort. But OpXxx
is not an existing concept at the binding side. How about using WriteOptions
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, the OpWriteOptions
concept corresponds to OpWrite
, so I think it's better to use one object not OpWriteOptions
, OpWriterOptions
the name starts with Op
also because of this, but WriteOptions
is ok for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, the
OpWriteOptions
concept corresponds toOpWrite
, so I think it's better to use one object notOpWriteOptions
,OpWriterOptions
Your understanding is correct. But there is a gap between rust core and nodejs binding.
Rust Core users have a concept called OpXxx
like OpWrite
and OpRead
. But we never expose those APIs to nodejs binding. So from the nodejs users view, they don't know about OpXxx
thus they can't understand what's OpXxx
represents for.
So I think it's better to use WriteOptions
without the Op
prefix.
And for WriteOptions
and WriterOptions
, it's possible for the future to introduce different options inside write
and writer
options. So I want to seperate them for now instead of another breaking changes in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that's a comprehensive explanation, I will fix it ASAP
bindings/nodejs/generated.d.ts
Outdated
/** | ||
* Write multiple bytes into path synchronously. | ||
* | ||
* It could be used to write large file in a streaming way. | ||
*/ | ||
writerSync(path: string): BlockingWriter | ||
writerSync(path: string, options?: OpWriteOptions | undefined | null): BlockingWriter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we need WriterOptions
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as I mentioned above, I think WriteOptions
is enough
bindings/nodejs/src/lib.rs
Outdated
@@ -30,6 +29,11 @@ use futures::AsyncReadExt; | |||
use futures::TryStreamExt; | |||
use napi::bindgen_prelude::*; | |||
|
|||
use opendal::operator_functions::{FunctionWrite, FunctionWriter}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better not to play with those APIs. What do you think about adding bunch of if-else
directly?
This PR also makes me thinking about exporting WriteOptions
from the rust core side. We can have a discussion there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean this?
let mut writer = self.0.write_with(&path, c);
if let Some(options) = options {
- writer = writer.with(options);
+ if let Some(append) = options.append {
+ writer = writer.append(append);
+ }
+ if let Some(chunk) = options.chunk {
+ writer = writer.chunk(chunk.get_u64().1 as usize);
+ }
+ if let Some(ref content_type) = options.content_type {
+ writer = writer.content_type(content_type);
+ }
+ if let Some(ref content_disposition) = options.content_disposition {
+ writer = writer.content_disposition(content_disposition);
+ }
+ if let Some(ref cache_control) = options.cache_control {
+ writer = writer.cache_control(cache_control);
+ }
}
writer.await.map_err(format_napi_error)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can polish here in the future if rust core exposes WriteOptions
directly.
OpWriteOptions
for write methodsWriteOptions
for write methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot!
close: #4782