Expand description
§Neo File Storage (NeoFS) Module (v0.4.1)
NeoFS is a decentralized distributed object storage network integrated with the Neo Blockchain. It provides a robust platform for storing, retrieving, and managing digital assets with blockchain-level security.
§Overview
This module provides Rust bindings to interact with NeoFS services, including:
- Container Management: Create, retrieve, list, and delete NeoFS containers
- Object Operations: Upload, download, and manage objects in containers
- Access Control: Manage permissions and generate access tokens
- Extended Features: Support for multipart uploads and specialized storage operations
§Example
ⓘ
use neo3::neo_fs::{NeoFSClient, NeoFSConfig};
use neo3::neo_fs::container::Container;
use neo3::neo_fs::object::{Object, ObjectId};
use neo3::neo_protocol::Account;
use std::path::Path;
async fn example() -> Result<(), Box<dyn std::error::Error>> {
// Create an account from a WIF for authentication
let account = Account::from_wif("KwVEKk78X65fDrJ3VgqHLcpPpbQVfJLjXrkFUCozHQBJ5nT2xwP8")?;
// Configure NeoFS client
let config = NeoFSConfig {
endpoint: "grpc+tls://st01.testnet.fs.neo.org:8082".to_string(),
auth: Some(neo3::neo_fs::NeoFSAuth {
wallet_address: account.get_address(),
private_key: account.key_pair().as_ref().map(|kp| kp.private_key().to_string()),
}),
timeout_sec: 30,
insecure: false,
};
// Initialize the NeoFS client
let client = NeoFSClient::new(config).await?;
// List available containers
let containers = client.list_containers().await?;
println!("Found {} containers", containers.len());
// Create a new container with basic attributes
let mut new_container = Container::new();
new_container.set_name("my-documents");
new_container.set_basic_acl(true, false); // Public read, private write
// Create the container in NeoFS
let container_id = client.create_container(&new_container).await?;
println!("Created container with ID: {}", container_id);
// Upload a file to the container
let file_path = Path::new("./example.txt");
let file_data = std::fs::read(file_path)?;
let mut object = Object::new();
object.set_file_name("example.txt");
object.set_data(file_data);
let object_id = client.put_object(&container_id, &object).await?;
println!("Uploaded object with ID: {}", object_id);
// Download the object
let retrieved_object = client.get_object(&container_id, &object_id).await?;
println!("Downloaded object: {} ({} bytes)",
retrieved_object.file_name(),
retrieved_object.data().len());
// Clean up - delete the object and container
client.delete_object(&container_id, &object_id).await?;
client.delete_container(&container_id).await?;
Ok(())
}
Re-exports§
pub use client::NeoFSClient;
pub use error::NeoFSError;
pub use error::NeoFSResult;
pub use acl::BearerToken;
pub use acl::SessionToken;
pub use container::Container;
pub use object::MultipartUpload;
pub use object::MultipartUploadResult;
pub use object::Object;
pub use object::Part;
pub use types::AccessPermission;
pub use types::Attributes;
pub use types::ContainerId;
pub use types::ObjectId;
pub use types::ObjectType;
pub use types::OwnerId;
pub use types::PlacementPolicy;
Modules§
- acl
- NeoFS Access Control
- client
- Client for interacting with NeoFS.
- container
- NeoFS Container
- error
- NeoFS Error Handling
- object
- NeoFS Object Operations
- types
- NeoFS Core Types
Structs§
- NeoFS
Auth - Authentication information for NeoFS
- NeoFS
Config - Represents a NeoFS service provider configuration
Constants§
- DEFAULT_
ENDPOINT - Default NeoFS endpoint
- DEFAULT_
MAINNET_ ENDPOINT - The default mainnet NeoFS endpoint
- DEFAULT_
TESTNET_ ENDPOINT - The default testnet NeoFS endpoint
Traits§
- NeoFS
Service - Service trait for interacting with NeoFS