Skip to content

Commit

Permalink
deps: Bump reqwest, reqsign and http (#4397)
Browse files Browse the repository at this point in the history
* deps: Bump reqwest, reqsign and http

Signed-off-by: Xuanwo <[email protected]>

* Fix cargo lock

Signed-off-by: Xuanwo <[email protected]>

* Size smaller

Signed-off-by: Xuanwo <[email protected]>

* Fix nodejs

Signed-off-by: Xuanwo <[email protected]>

* Fix unit tests

Signed-off-by: Xuanwo <[email protected]>

---------

Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Mar 26, 2024
1 parent c997590 commit 7ccc8a8
Show file tree
Hide file tree
Showing 12 changed files with 741 additions and 428 deletions.
File renamed without changes.
257 changes: 147 additions & 110 deletions bin/oay/Cargo.lock

Large diffs are not rendered by default.

270 changes: 132 additions & 138 deletions bin/ofs/Cargo.lock

Large diffs are not rendered by default.

277 changes: 191 additions & 86 deletions bin/oli/Cargo.lock

Large diffs are not rendered by default.

39 changes: 15 additions & 24 deletions bindings/nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ extern crate napi_derive;
mod capability;

use std::collections::HashMap;
use std::fmt::Display;
use std::io::Read;
use std::str::FromStr;
use std::time::Duration;

use futures::TryStreamExt;
use futures::{AsyncReadExt, TryStreamExt};
use napi::bindgen_prelude::*;

#[napi]
Expand Down Expand Up @@ -181,10 +183,10 @@ impl Operator {
/// It could be used to read large file in a streaming way.
#[napi]
pub async fn reader(&self, path: String) -> Result<Reader> {
let meta = self.0.stat(&path).await.map_err(format_napi_error)?;
let r = self.0.reader(&path).await.map_err(format_napi_error)?;
Ok(Reader {
inner: r,
offset: 0,
inner: r.into_futures_io_async_read(0..meta.content_length()),
})
}

Expand All @@ -205,10 +207,10 @@ impl Operator {
/// It could be used to read large file in a streaming way.
#[napi]
pub fn reader_sync(&self, path: String) -> Result<BlockingReader> {
let meta = self.0.blocking().stat(&path).map_err(format_napi_error)?;
let r = self.0.blocking().reader(&path).map_err(format_napi_error)?;
Ok(BlockingReader {
inner: r,
offset: 0,
inner: r.into_std_io_read(0..meta.content_length()),
})
}

Expand Down Expand Up @@ -648,21 +650,15 @@ pub struct ListOptions {
/// manner.
#[napi]
pub struct BlockingReader {
inner: opendal::BlockingReader,
offset: u64,
inner: opendal::StdIoReader,
}

#[napi]
impl BlockingReader {
#[napi]
pub fn read(&mut self, mut buf: Buffer) -> Result<usize> {
let mut buf = buf.as_mut();
let size = buf.len();
let n = self
.inner
.read(&mut buf, self.offset, size)
.map_err(format_napi_error)?;
self.offset += n as u64;
let buf = buf.as_mut();
let n = self.inner.read(buf).map_err(format_napi_error)?;
Ok(n)
}
}
Expand All @@ -671,8 +667,7 @@ impl BlockingReader {
/// manner.
#[napi]
pub struct Reader {
inner: opendal::Reader,
offset: u64,
inner: opendal::FuturesIoAsyncReader,
}

#[napi]
Expand All @@ -685,13 +680,7 @@ impl Reader {
#[napi]
pub async unsafe fn read(&mut self, mut buf: Buffer) -> Result<usize> {
let mut buf = buf.as_mut();
let size = buf.len();
let n = self
.inner
.read(&mut buf, self.offset, size)
.await
.map_err(format_napi_error)?;
self.offset += n as u64;
let n = self.inner.read(&mut buf).await.map_err(format_napi_error)?;
Ok(n)
}
}
Expand Down Expand Up @@ -1008,6 +997,8 @@ impl RetryLayer {
}

/// Format opendal error to napi error.
fn format_napi_error(err: opendal::Error) -> Error {
///
/// FIXME: handle error correctly.
fn format_napi_error(err: impl Display) -> Error {
Error::from_reason(format!("{}", err))
}
Loading

0 comments on commit 7ccc8a8

Please sign in to comment.