summaryrefslogtreecommitdiff
path: root/ext/web/blob.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-06-22 23:37:56 +0200
committerGitHub <noreply@github.com>2023-06-22 23:37:56 +0200
commitdda0f1c343bfb3196ce6a7c7e8c2acccfd5c2e5b (patch)
tree10fc273a620949ccf63826363499f8f39056896d /ext/web/blob.rs
parentb319fa7f4965af3d3d576ea528248a31c96a4053 (diff)
refactor(serde_v8): split ZeroCopyBuf into JsBuffer and ToJsBuffer (#19566)
`ZeroCopyBuf` was convenient to use, but sometimes it did hide details that some copies were necessary in certain cases. Also it made it way to easy for the caller to pass around and convert into different values. This commit splits `ZeroCopyBuf` into `JsBuffer` (an array buffer coming from V8) and `ToJsBuffer` (a Rust buffer that will be converted into a V8 array buffer). As a result some magical conversions were removed (they were never used) limiting the API surface and preparing for changes in #19534.
Diffstat (limited to 'ext/web/blob.rs')
-rw-r--r--ext/web/blob.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/ext/web/blob.rs b/ext/web/blob.rs
index 7796c18af..9c5f5a09c 100644
--- a/ext/web/blob.rs
+++ b/ext/web/blob.rs
@@ -12,8 +12,9 @@ use deno_core::error::AnyError;
use deno_core::op;
use deno_core::parking_lot::Mutex;
use deno_core::url::Url;
+use deno_core::JsBuffer;
use deno_core::OpState;
-use deno_core::ZeroCopyBuf;
+use deno_core::ToJsBuffer;
use serde::Deserialize;
use serde::Serialize;
use uuid::Uuid;
@@ -160,7 +161,7 @@ impl BlobPart for SlicedBlobPart {
}
#[op]
-pub fn op_blob_create_part(state: &mut OpState, data: ZeroCopyBuf) -> Uuid {
+pub fn op_blob_create_part(state: &mut OpState, data: JsBuffer) -> Uuid {
let blob_store = state.borrow::<BlobStore>();
let part = InMemoryBlobPart(data.to_vec());
blob_store.insert_part(Arc::new(part))
@@ -203,7 +204,7 @@ pub fn op_blob_slice_part(
pub async fn op_blob_read_part(
state: Rc<RefCell<OpState>>,
id: Uuid,
-) -> Result<ZeroCopyBuf, AnyError> {
+) -> Result<ToJsBuffer, AnyError> {
let part = {
let state = state.borrow();
let blob_store = state.borrow::<BlobStore>();
@@ -211,7 +212,7 @@ pub async fn op_blob_read_part(
}
.ok_or_else(|| type_error("Blob part not found"))?;
let buf = part.read().await?;
- Ok(ZeroCopyBuf::from(buf.to_vec()))
+ Ok(ToJsBuffer::from(buf.to_vec()))
}
#[op]