5 releases
| 0.1.6 | Sep 20, 2025 |
|---|---|
| 0.1.5 | Aug 16, 2025 |
| 0.1.4 | Aug 15, 2025 |
| 0.1.2 | Jul 13, 2025 |
| 0.1.0 | Jul 13, 2025 |
#2891 in Data structures
431 downloads per month
56KB
1K
SLoC
file-mumu
File handling functions and streams plugin for the Lava language / Mumu engine
Overview
mumu-file provides Lava/Mumu scripts with file reading, writing, and streaming capabilities.
It supports synchronous and streaming I/O, large file handling, and is suitable for both direct scripting and use as a dynamic plugin.
- Read files (entire or as streams/chunks)
- Write files (sync, streaming, or with iterators/transforms)
- Integrates natively with Lava's function system
Features
file:read— Read files as a string or in streaming/chunked mode.file:write— Write data, arrays, iterators, or streaming transforms to files.file:stream— Utility for chunked streaming to stdout.
Fully asynchronous at the Rust level (threaded), with Lava/Ink integration for safe, ergonomic script access.
Installation
As a Rust plugin
Add to your Cargo.toml:
[dependencies]
mumu-file = "0.1"
Building for Lava/Mumu
Clone and build (Linux example):
git clone https://gitlab.com/tofo/mumu-file.git
cd mumu-file
make
make install
This installs the libmumufile.so plugin to /usr/local/lib/, making it available for Lava/Mumu.
Usage
In Lava/Mumu scripts
extend("file")
# Synchronous read
file:read("hello.txt", (data) => {
slog("File contents:", data)
})
# Streaming read (chunked)
file:read("bigfile.txt", file:stream)
# Synchronous write
file:write("out.txt", "Hello, world!")
# Write from array
file:write("numbers.txt", [1,2,3,4])
# Partial application
let write_hello = file:write("out.txt")
write_hello("Extra text")
# Stream-based write (see docs)
In Rust
use mumu_file; // (libmumufile.so)
The plugin is loaded dynamically by Lava/Mumu via extend("file").
Direct usage as a Rust crate is possible for advanced users; see API docs for details.
API
file:read(path, callback)
- Reads a file and invokes the callback with the contents.
- If the callback is
file:stream, reads in chunks (for large files). - Returns
trueon start; actual results are passed to the callback.
file:write(path, data)
- Writes data to a file. Data may be:
- a string
- an array
- an iterator (for large/growing data)
- a transform (function)
- Supports partial application:
let writer = file:write(path)returns a function.
file:stream(chunk)
- Prints a chunk (usually from a streaming read) to stdout with no newline.
- If chunk is empty, closes stream.
Minimum Supported Rust Version (MSRV)
Rust 1.60 or newer.
License
Licensed under either of:
- MIT license (LICENSE-MIT or https://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
at your option.
Links
Author
Tom Fotheringham tom@nu11.co.uk
Dependencies
~3.5–5MB
~82K SLoC