Skip to content

Commit e1368f5

Browse files
committed
Remove reader and writer and hide opfs API.
1 parent a7a5a05 commit e1368f5

File tree

8 files changed

+23
-294
lines changed

8 files changed

+23
-294
lines changed

core/src/services/opfs/backend.rs

Lines changed: 15 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@
1818
use serde::Deserialize;
1919
use std::sync::Arc;
2020

21-
use super::{lister::OpfsLister, reader::OpfsReader, writer::OpfsWriter};
22-
use crate::{
23-
raw::{Access, AccessorInfo, OpRead, OpWrite, RpRead, RpWrite},
24-
Builder, Capability, Error, Result, Scheme,
25-
};
21+
use crate::raw::{Access, AccessorInfo};
2622
use std::fmt::Debug;
2723

2824
/// Origin private file system (OPFS) configuration
@@ -52,101 +48,38 @@ impl Debug for OpfsBuilder {
5248
}
5349
}
5450

55-
impl Builder for OpfsBuilder {
56-
const SCHEME: Scheme = Scheme::Opfs;
57-
58-
type Config = ();
59-
60-
fn build(self) -> Result<impl Access> {
61-
Ok(OpfsBackend {})
62-
}
63-
}
51+
// impl Builder for OpfsBuilder {
52+
// const SCHEME: Scheme = Scheme::Opfs;
53+
//
54+
// type Config = ();
55+
//
56+
// fn build(self) -> Result<impl Access> {
57+
// Ok(OpfsBackend {})
58+
// }
59+
// }
6460

6561
/// OPFS Service backend
6662
#[derive(Debug, Clone)]
6763
pub struct OpfsBackend {}
6864

6965
impl Access for OpfsBackend {
70-
type Reader = OpfsReader;
66+
type Reader = ();
7167

72-
type Writer = OpfsWriter;
68+
type Writer = ();
7369

74-
type Lister = OpfsLister;
70+
type Lister = ();
7571

7672
type Deleter = ();
7773

7874
type BlockingReader = ();
7975

8076
type BlockingWriter = ();
8177

82-
type BlockingLister = OpfsLister;
78+
type BlockingLister = ();
8379

8480
type BlockingDeleter = ();
8581

8682
fn info(&self) -> Arc<AccessorInfo> {
87-
let access_info = AccessorInfo::default();
88-
access_info
89-
.set_scheme(Scheme::Opfs)
90-
.set_native_capability(Capability {
91-
stat: false,
92-
read: true,
93-
write: true,
94-
write_can_empty: true,
95-
write_can_append: true,
96-
write_can_multi: true,
97-
create_dir: false,
98-
delete: false,
99-
list: false,
100-
copy: false,
101-
rename: false,
102-
blocking: true,
103-
..Default::default()
104-
});
105-
Arc::new(access_info)
106-
}
107-
108-
async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> {
109-
let path = path.to_owned();
110-
111-
Ok::<(RpRead, Self::Reader), Error>((
112-
RpRead::default(),
113-
OpfsReader::new(args.range(), path),
114-
))
115-
}
116-
async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::Writer)> {
117-
// Access the OPFS
118-
let path = path.to_owned();
119-
120-
Ok((RpWrite::default(), OpfsWriter::new(path, args.append())))
121-
}
122-
}
123-
124-
#[cfg(test)]
125-
#[cfg(target_arch = "wasm32")]
126-
mod opfs_tests {
127-
use wasm_bindgen::prelude::*;
128-
use wasm_bindgen_test::*;
129-
130-
use std::collections::HashMap;
131-
132-
use crate::Operator;
133-
134-
use super::*;
135-
136-
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
137-
138-
#[wasm_bindgen]
139-
pub async fn test_opfs() -> String {
140-
let map = HashMap::new();
141-
let op = Operator::via_map(Scheme::Opfs, map).unwrap();
142-
let bs = op.read("path/to/file").await.unwrap();
143-
"ok".to_string()
144-
}
145-
146-
#[wasm_bindgen_test]
147-
async fn basic_test() -> Result<()> {
148-
let s = test_opfs().await;
149-
assert_eq!(s, "ok".to_string());
150-
Ok(())
83+
todo!()
15184
}
15285
}

core/src/services/opfs/core.rs

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,25 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use crate::Error;
1918
use crate::Result;
2019
use std::fmt::Debug;
21-
use std::future::Future;
22-
use tokio::sync::oneshot;
2320

2421
use web_sys::{
2522
window, File, FileSystemDirectoryHandle, FileSystemFileHandle, FileSystemGetFileOptions,
2623
FileSystemWritableFileStream,
2724
};
2825

2926
use wasm_bindgen::{JsCast, JsValue};
30-
use wasm_bindgen_futures::JsFuture;
31-
32-
fn spawn_local<F, T>(fut: F) -> impl Future<Output = T> + Send
33-
where
34-
F: Future<Output = T> + 'static,
35-
T: 'static + Send + Sync,
36-
{
37-
let (tx, rx) = oneshot::channel();
38-
wasm_bindgen_futures::spawn_local(async move {
39-
let item = fut.await;
40-
tx.send(item).expect_err("Failed to send completion signal");
41-
});
42-
async move { rx.await.unwrap() }
43-
}
4427

45-
#[derive(Default, Clone)]
28+
use wasm_bindgen_futures::JsFuture;
29+
#[derive(Default, Clone, Debug)]
4630
pub struct OpfsCore {}
4731

48-
impl Debug for OpfsCore {
49-
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50-
panic!()
51-
}
52-
}
53-
5432
impl OpfsCore {
5533
/// Write whole file
56-
///
57-
/// Return future is not send, because JsValue rely on slab(table to map JsValue(rust) to js variable).
34+
// Return future is not send, because JsValue rely on slab(table to map JsValue(rust) to js variable).
35+
//
36+
// consider using wasm_bindgen_futures::spawn_local
5837
async fn store_file(&self, file_name: &str, content: &[u8]) -> Result<(), JsValue> {
5938
// Access the OPFS
6039
let navigator = window().unwrap().navigator();
@@ -90,18 +69,11 @@ impl OpfsCore {
9069

9170
Ok(())
9271
}
93-
pub async fn store_file_send(self, filename: String, content: Vec<u8>) -> Result<(), Error> {
94-
spawn_local(async move {
95-
self.store_file(&filename, &content)
96-
.await
97-
.map_err(Error::from)
98-
})
99-
.await
100-
}
10172

10273
/// Read whole file
103-
///
104-
/// Return future is not send, because JsValue rely on slab(table to map JsValue(rust) to js variable).
74+
// Return future is not send, because JsValue rely on slab(table to map JsValue(rust) to js variable).
75+
//
76+
// consider using wasm_bindgen_futures::spawn_local
10577
async fn read_file(&self, file_name: &str) -> Result<Vec<u8>, JsValue> {
10678
// Access the OPFS
10779
let navigator = window()
@@ -128,7 +100,4 @@ impl OpfsCore {
128100

129101
Ok(vec)
130102
}
131-
pub async fn read_file_send(self, file_name: String) -> Result<Vec<u8>, Error> {
132-
spawn_local(async move { self.read_file(&file_name).await.map_err(Error::from) }).await
133-
}
134103
}

core/src/services/opfs/helper.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

core/src/services/opfs/lister.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

core/src/services/opfs/mod.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,5 @@ mod backend;
2121
mod core;
2222
#[cfg(feature = "services-opfs")]
2323
mod error;
24-
#[cfg(feature = "services-opfs")]
25-
mod helper;
26-
#[cfg(feature = "services-opfs")]
27-
mod lister;
28-
#[cfg(feature = "services-opfs")]
29-
mod reader;
30-
#[cfg(feature = "services-opfs")]
31-
mod writer;
32-
3324
#[cfg(feature = "services-opfs")]
3425
pub use backend::OpfsBuilder as Opfs;

core/src/services/opfs/reader.rs

Lines changed: 0 additions & 48 deletions
This file was deleted.

core/src/services/opfs/writer.rs

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)