Module utils

Module utils 

Source
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§

BlockInfo
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.