-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add support for opfs * feat: remove tokio fs feature required * opfs read by stream * add example * remove useless code * opfs for parquet * add ci for wasm build * add ci for aws building in wasm * fix opfs read_exact_at buf too large * add wasm test ci * error handling * chore: bump fusio to 0.3.1 (#86) * feat: impl `BufReader` (#84) * feat: Add basic layout for fusio-opendal (#89) * feat: Add basic layout for fusio-opendal Signed-off-by: Xuanwo <github@xuanwo.io> * ci: Add CI check for fusio-opendal Signed-off-by: Xuanwo <github@xuanwo.io> * chore: Remove not needed feature flags Signed-off-by: Xuanwo <github@xuanwo.io> --------- Signed-off-by: Xuanwo <github@xuanwo.io> * docs: Update Compare to OpenDAL (#90) * docs: Update Compare to OpenDAL * Polish the full ecosystem * feat: support custom endpoints (#87) * docs: Add example for fusio_opendal (#92) * docs: Add example for fusio_opendal Signed-off-by: Xuanwo <github@xuanwo.io> * chore: format --------- Signed-off-by: Xuanwo <github@xuanwo.io> Co-authored-by: Gwo Tzu-Hsing <gotzehsing@gmail.com> * resolve error * fix: unexpected tokio required in fusio-parquet * fix opfs read eof --------- Signed-off-by: Xuanwo <github@xuanwo.io> Co-authored-by: Gwo Tzu-Hsing <gotzehsing@gmail.com> Co-authored-by: Kould <kould2333@gmail.com> Co-authored-by: Xuanwo <github@xuanwo.io>
- Loading branch information
1 parent
1b18476
commit 8038993
Showing
23 changed files
with
1,382 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[workspace] | ||
members = [ | ||
"examples", | ||
"examples/opfs", | ||
"fusio", | ||
"fusio-dispatch", | ||
"fusio-object-store", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package-lock.json | ||
pkg | ||
dist | ||
wasm-pack.log | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[package] | ||
name = "example-opfs" | ||
edition.workspace = true | ||
license.workspace = true | ||
version = "0.1.0" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "rlib"] | ||
|
||
[dependencies] | ||
arrow = "53" | ||
fusio = { path = "../../fusio", features = ["opfs"] } | ||
fusio-dispatch = { path = "../../fusio-dispatch", features = ["opfs"] } | ||
fusio-parquet = { path = "../../fusio-parquet", features = ["opfs"] } | ||
futures = { version = "0.3" } | ||
parquet = { version = "53", default-features = false, features = [ | ||
"arrow", | ||
"async", | ||
] } | ||
wasm-bindgen = "0.2.95" | ||
wasm-bindgen-futures = { version = "0.4.45" } | ||
web-sys = { version = "0.3", features = [ | ||
"console", | ||
|
||
] } | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.3.34" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { async_reader, async_writer, read_from_opfs, remove_all_dir, write_to_opfs } from "./pkg"; | ||
|
||
await write_to_opfs(); | ||
await read_from_opfs(); | ||
|
||
await async_writer(); | ||
await async_reader(); | ||
|
||
await remove_all_dir(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"scripts": { | ||
"build": "webpack", | ||
"serve": "webpack serve" | ||
}, | ||
"devDependencies": { | ||
"@wasm-tool/wasm-pack-plugin": "1.5.0", | ||
"html-webpack-plugin": "^5.6.0", | ||
"webpack": "^5.93.0", | ||
"webpack-cli": "^5.1.4", | ||
"webpack-dev-server": "^5.0.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
use std::sync::Arc; | ||
|
||
use arrow::array::{ArrayRef, Int64Array, RecordBatch}; | ||
use fusio::{fs::OpenOptions, path::Path, Read, Write}; | ||
use fusio_dispatch::FsOptions; | ||
use fusio_parquet::{reader::AsyncReader, writer::AsyncWriter}; | ||
use futures::StreamExt; | ||
use parquet::arrow::{AsyncArrowWriter, ParquetRecordBatchStreamBuilder}; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[wasm_bindgen] | ||
pub async fn write_to_opfs() { | ||
let fs_options = FsOptions::Local; | ||
let fs = fs_options.parse().unwrap(); | ||
let mut file = fs | ||
.open_options( | ||
&Path::from_opfs_path("foo").unwrap(), | ||
OpenOptions::default().create(true), | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
let write_buf = "hello, fusio".as_bytes(); | ||
|
||
let (result, buf) = file.write_all(write_buf).await; | ||
result.unwrap(); | ||
|
||
file.close().await.unwrap(); | ||
web_sys::console::log_1(&format!("write data: {:?}", buf).into()); | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn read_from_opfs() { | ||
let fs_options = FsOptions::Local; | ||
let fs = fs_options.parse().unwrap(); | ||
let mut file = fs | ||
.open(&Path::from_opfs_path("foo").unwrap()) | ||
.await | ||
.unwrap(); | ||
|
||
let (result, read_buf) = file.read_to_end_at(vec![], 0).await; | ||
result.unwrap(); | ||
assert_eq!(read_buf.as_slice(), b"hello, fusio"); | ||
web_sys::console::log_1(&format!("read data: {:?}", read_buf).into()); | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn async_writer() { | ||
let fs_options = FsOptions::Local; | ||
let fs = fs_options.parse().unwrap(); | ||
let file = fs | ||
.open_options( | ||
&Path::from_opfs_path("bar").unwrap(), | ||
OpenOptions::default().create(true), | ||
) | ||
.await | ||
.unwrap(); | ||
let writer = AsyncWriter::new(file); | ||
let col = Arc::new(Int64Array::from_iter_values([1, 2, 3])) as ArrayRef; | ||
let to_write = RecordBatch::try_from_iter([("col", col)]).unwrap(); | ||
let mut writer = AsyncArrowWriter::try_new(writer, to_write.schema(), None).unwrap(); | ||
writer.write(&to_write).await.unwrap(); | ||
writer.close().await.unwrap(); | ||
web_sys::console::log_1(&format!("write data: {:?} to parquet", to_write).into()); | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn async_reader() { | ||
let fs_options = FsOptions::Local; | ||
let fs = fs_options.parse().unwrap(); | ||
let file = fs | ||
.open(&Path::from_opfs_path("bar").unwrap()) | ||
.await | ||
.unwrap(); | ||
|
||
let size = file.size().await.unwrap(); | ||
let reader = AsyncReader::new(file, size).await.unwrap(); | ||
let mut stream = ParquetRecordBatchStreamBuilder::new(reader) | ||
.await | ||
.unwrap() | ||
.build() | ||
.unwrap(); | ||
|
||
let read = stream.next().await.unwrap().unwrap(); | ||
|
||
let col = Arc::new(Int64Array::from_iter_values([1, 2, 3])) as ArrayRef; | ||
let expected = RecordBatch::try_from_iter([("col", col)]).unwrap(); | ||
assert_eq!(expected, read); | ||
web_sys::console::log_1(&format!("read data: {:?} from parquet", read).into()); | ||
} | ||
#[wasm_bindgen] | ||
pub async fn remove_all_dir() { | ||
let fs_options = FsOptions::Local; | ||
let fs = fs_options.parse().unwrap(); | ||
fs.remove(&Path::from_opfs_path("foo").unwrap()) | ||
.await | ||
.unwrap(); | ||
fs.remove(&Path::from_opfs_path("bar").unwrap()) | ||
.await | ||
.unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const path = require("path"); | ||
const HtmlWebpackPlugin = require("html-webpack-plugin"); | ||
const webpack = require("webpack"); | ||
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin"); | ||
|
||
module.exports = { | ||
entry: "./index.js", | ||
output: { | ||
path: path.resolve(__dirname, "dist"), | ||
filename: "index.js", | ||
}, | ||
mode: "development", | ||
plugins: [ | ||
new HtmlWebpackPlugin(), | ||
new WasmPackPlugin({ | ||
crateDirectory: path.resolve(__dirname, "."), | ||
}), | ||
], | ||
experiments: { | ||
asyncWebAssembly: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.