mirror of
https://github.com/fluencelabs/examples
synced 2025-06-23 14:51:33 +00:00
intro: 4-ipfs-code-execution (#15)
This commit is contained in:
4
intro/4-ipfs-code-execution/service/.gitignore
vendored
Normal file
4
intro/4-ipfs-code-execution/service/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
debug/
|
||||
target/
|
||||
**/*.bk
|
||||
**/*.bak
|
21
intro/4-ipfs-code-execution/service/Cargo.toml
Normal file
21
intro/4-ipfs-code-execution/service/Cargo.toml
Normal file
@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "process_files"
|
||||
version = "0.1.0"
|
||||
authors = ["Fluence Labs"]
|
||||
edition = "2018"
|
||||
description = "Marine service that processes files in various ways"
|
||||
license = "Apache-2.0"
|
||||
|
||||
[[bin]]
|
||||
name = "process_files"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
marine-rs-sdk = { version="0.6.11", features=["logger"] }
|
||||
log = "0.4.14"
|
||||
|
||||
[dev-dependencies]
|
||||
marine-rs-sdk-test = "0.1.11"
|
||||
|
||||
[profile.release]
|
||||
opt-level = "s"
|
6
intro/4-ipfs-code-execution/service/Config.toml
Normal file
6
intro/4-ipfs-code-execution/service/Config.toml
Normal file
@ -0,0 +1,6 @@
|
||||
modules_dir = "artifacts/"
|
||||
|
||||
[[module]]
|
||||
name = "process_files"
|
||||
mem_pages_count = 1
|
||||
logger_enabled = true
|
8
intro/4-ipfs-code-execution/service/scripts/build.sh
Executable file
8
intro/4-ipfs-code-execution/service/scripts/build.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash -o errexit -o nounset -o pipefail
|
||||
cargo update --aggressive
|
||||
|
||||
mkdir -p artifacts
|
||||
rm -f artifacts/*.wasm
|
||||
marine build --release
|
||||
cp target/wasm32-wasi/release/process_files.wasm artifacts/
|
||||
marine aqua artifacts/process_files.wasm >../aqua/process_files.aqua
|
37
intro/4-ipfs-code-execution/service/src/main.rs
Normal file
37
intro/4-ipfs-code-execution/service/src/main.rs
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2021 Fluence Labs Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use marine_rs_sdk::{marine, module_manifest};
|
||||
|
||||
module_manifest!();
|
||||
|
||||
pub fn main() { }
|
||||
|
||||
#[marine]
|
||||
pub struct SizeResult {
|
||||
pub size: u32,
|
||||
pub success: bool,
|
||||
pub error: String,
|
||||
}
|
||||
|
||||
#[marine]
|
||||
pub fn file_size(file_path: String) -> SizeResult {
|
||||
match std::fs::read(file_path) {
|
||||
Ok(bytes) => SizeResult { size: bytes.len() as _, success: true, error: String::new() },
|
||||
Err(err) => SizeResult { size: 0, success: false, error: err.to_string() },
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user