This repository is deprecated! We've moved all EO objects from this repository to objectionary/eo.
EO objects for file system.
This is how you list all text files in a directory recursively:
each. > @
filteredi.
QQ.collections.list
walk.
QQ.fs.dir "/tmp"
"**/*"
[f i]
and. > @
f.is-dir.not
matches.
compile.
QQ.txt.regex
"/.*\\.txt$/"
f
[f]
QQ.io.stdout > @
QQ.txt.sprintf "file: %s\n" f
You are welcome to add more primitives to this lib.
Simple manipulations:
# Make a new object representing a file on disc
QQ.fs.file > f
"/tmp/foo.txt"
# Get its name:
QQ.io.stdout
QQ.txt.sprintf
"File name is: %s"
f
# Does it exist?
f.exists
# Is it a directory?
f.is-dir
# Touch it, to make sure it exists
f.touch
# Delete the file:
f.rm
# Rename/move it:
f.mv "/tmp/bar.txt"
# Get the size of it in bytes:
f.size > s
Reading:
# Read binary content into the "output," in 1024-bytes chunks;
# the "memory-as-output" is an abstract object with one free attribute,
# which is the memory where the bytes will be stored:
QQ.fs.file "/tmp/foo.txt" > f
memory > m
QQ.io.copied
f.as-input
QQ.io.memory-as-output m
1024
Writing:
# Write binary content, taking it from the "input",
# until input turns into a non-empty "bytes"; here the
# "mode" is the same as the mode in POSIX fopen();
# if the file is absent, it will be created:
QQ.fs.file "/tmp/foo.txt" > f
QQ.io.copied
QQ.io.bytes-as-input
"你好, world!".as-bytes
f.as-output "w+"
Smart object to help read content fast:
# This is the entire binary content of the file:
QQ.fs.content f
Directories:
# Make an object representing a directory on disc:
QQ.fs.directory > d
"/tmp"
# Make it if doesn't exist:
d.mkdir
# Delete it recursively:
d.rm-rf
# List all files recursively:
d.walk "**/*.txt"
Temporary files:
# This is a system directory for temporary files:
QQ.fs.tmpdir > d
# Create an empty temporary file in a directory
d.tmpfile.@ > f
Name manipulations:
# Add path segment to existing file:
QQ.fs.file "/tmp" > f
f.resolve "foo.txt"
# Get directory name:
QQ.fs.dir-name f
# Get base name (no directory, not extension):
QQ.fs.base-name f
# Get extension:
QQ.fs.ext-name f
Fork repository, make changes, send us a pull request.
We will review your changes and apply them to the master
branch shortly,
provided they don't violate our quality standards. To avoid frustration,
before sending us your pull request please run full Maven build:
$ mvn clean install -Pqulice
You will need Maven 3.3+ and Java 8+.