Expand description
Utility functions for common IPFRS operations.
This module provides convenience functions that simplify common tasks when working with blocks, CIDs, and IPLD data.
§Examples
use ipfrs_core::utils;
use bytes::Bytes;
// Quick block creation with default settings
let block = utils::quick_block(b"Hello, World!").unwrap();
println!("CID: {}", block.cid());
// Parse CID from string
let cid = utils::parse_cid_string("QmXXX...").ok();Structs§
- Block
Info - Information about a block for diagnostic purposes.
- CidInfo
- Information about a CID for diagnostic purposes.
Functions§
- blake2b256_
cid - Computes a BLAKE2b-256 CID (fast, 32-byte hash).
- blake2b512_
cid - Computes a BLAKE2b-512 CID (fast, 64-byte hash).
- blake2s256_
cid - Computes a BLAKE2s-256 CID (fast, optimized for 8-32 bit platforms).
- blake3_
cid - Computes a BLAKE3 CID (fastest, modern cryptographic design).
- block_
with_ hash - Creates a block with a specific hash algorithm.
- blocks_
equal - Checks if two blocks have the same CID (content equality).
- cid_of
- Computes the CID of data using the specified hash algorithm.
- compress_
block_ data - Compress a block’s data with the specified algorithm and level
- count_
unique_ blocks - Counts the number of unique CIDs in a collection of blocks.
- decompress_
block_ data - Decompress block data that was previously compressed
- deduplication_
ratio - Calculates the deduplication ratio for a collection of blocks.
- estimate_
chunks - Estimates the number of chunks needed for data of the given size.
- estimate_
compression_ savings - Estimate how much space would be saved by compressing the data
- find_
invalid_ blocks - Finds blocks in a collection that have invalid CIDs (mismatched content).
- format_
size - Formats a block size in human-readable format (KB, MB, GB).
- inspect_
block - Inspects a block and returns detailed diagnostic information.
- inspect_
cid - Inspects a CID and returns detailed diagnostic information.
- ipld_
from_ cbor - Decodes IPLD data from DAG-CBOR bytes.
- ipld_
from_ json - Decodes IPLD data from DAG-JSON string.
- ipld_
list - Creates an IPLD list from values.
- ipld_
map - Creates an IPLD map from key-value pairs.
- ipld_
to_ cbor - Encodes IPLD data to DAG-CBOR bytes.
- ipld_
to_ json - Encodes IPLD data to DAG-JSON string.
- measure_
block_ creation - Measures the time taken to create a block from the given data.
- measure_
cid_ generation - Measures the time taken to generate a CID for the given data.
- needs_
chunking - Checks if data needs chunking based on the maximum block size.
- parse_
cid_ string - Parses a CID from a string with automatic multibase detection.
- quick_
block - Creates a block from a byte slice using default settings (SHA2-256, CIDv1, raw codec).
- recommended_
compression - Get recommended compression algorithm based on use case
- sha3_
512_ cid - Computes a SHA3-512 CID (64-byte Keccak hash).
- sha3_
cid - Computes a SHA3-256 CID.
- sha256_
cid - Computes a SHA2-256 CID (most common).
- sha512_
cid - Computes a SHA2-512 CID (64-byte hash).
- should_
compress - Check if data is worth compressing based on size and estimated ratio
- total_
blocks_ size - Calculates the total size of all blocks in bytes.
- validate_
blocks - Validates a collection of blocks, returning the number of valid and invalid blocks.
- validate_
cid_ string - Validates that a string is a valid CID.
- verify_
block - Verifies that a block’s CID matches its content.