mumu-file

Crates.iomumu-file
lib.rsmumu-file
version0.1.0
created_at2025-06-22 11:24:13.97+00
updated_at2025-06-22 11:24:13.97+00
descriptionFile handling function and steams plugin for the Lava language
homepagehttps://lava.nu11.uk
repositoryhttps://gitlab.com/tofo/mumu-file
max_upload_size
id1721586
size62,078
(rusty-shrimp)

documentation

README

mumu-file

File handling functions and streams plugin for the Lava language / Mumu engine

crates.io License: MIT OR Apache-2.0


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 true on 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:

at your option.


Links


Author

Tom Fotheringham tom@nu11.co.uk

Commit count: 0

cargo fmt