Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
iotdb-fs
Advanced tools
Readme
Pipeline Oriented Programming (POP) FS functions
There is sample code in samples/fs.js
.
All examples set up with:
const _ = require("iotdb-helpers")
const fs = require("iotdb-fs")
Note that this can probably be used async
style, but I haven't tried it
let self;
self = await fs.list({ path: "." })
self = await fs.all(fs.read.json)(self)
console.log(self.jsons)
fs.all
: apply a function to all self.paths
The results are returned in:
self.jsons
- all valid JSON resultsself.documents
- all valid documentsself.outputs
- all resultsEach output
looks like:
self.path
- the pathself.json
- JSON document, if anyself.document
- document, if anyself.document_media_type
- media type, if anyself.error
- error reported, if anyFailures will reported in self.outputs
.
sd.jsons
will only contain files successfully read
_.promise.make({
path: ".",
fs$filter_name: name => name.endsWith(".json"),
})
.then(fs.list)
.then(fs.all(fs.read.json))
.then(sd => console.log("+", "ok", sd.jsons))
_.promise.make({
path: ".",
})
.then(fs.list)
.then(fs.all(fs.read.utf8))
.then(sd => console.log("+", "ok", sd.documents))
fs.list
: list contents of a folder_.promise.make({
path: ".",
})
.then(fs.list)
.then(sd => console.log("+", "ok", sd.paths))
_.promise.make({
path: ".",
})
.then(fs.list.recursive)
.then(sd => console.log("+", "ok", sd.paths))
filter
checks the filename. filter_path
is also available.
This will only return files named *.json
.
_.promise.make({
path: ".",
fs$file_name: name => name.endsWith(".json"),
})
.then(fs.list.recursive)
.then(sd => console.log("+", "ok", sd.paths))
parer
checks the filename; if it does not match that particular
file will not be considered for recursion.
parer_path
is also available.
In the following examples, files in the .git
folder are ignored
(note that the .git
folder itself will be listed).
_.promise.make({
path: ".",
fs$parer_name: name === ".git",
})
.then(fs.list.recursive)
.then(sd => console.log("+", "ok", sd.paths))
_.promise.make({
path: ".",
fs$parer_name: name === ".git",
})
.then(fs.list.depth_first)
.then(sd => console.log("+", "ok", sd.paths))
_.promise.make({
path: ".",
fs$sorter: fs.sorter.natural_ignore_case,
})
.then(fs.list)
.then(sd => console.log("+", "ok", sd.paths))
Options (so far) are:
fs.sorter.natural
- A, B, C, a, b, c,fs.sorter.natural_ignore_case
- A, a, B, b, C, cWe need to add an option for a locale-sensitive sort
fs.make.directory
: make directoriesNote that no error is reported if the folder already exists
_.promise.make({
path: "delete-me",
})
.then(fs.make.directory.parent)
fs.make.directory.parent
- make parent folder_.promise.make({
path: "delete-me/write-json.json",
json: { "hello": "world" },
})
.then(fs.make.directory.parent)
.then(fs.write.json)
fs.read
- read filesReading documents will modify:
self.document
self.document_media_type
The document
may be a String or Buffer depending
on the function you choose.
The one except is fs.read.json
, that returns
its result in self.json
fs.read
- prefer versions belowfs.read.buffer
- read into bufferfs.read.json
- read into JSON_.promise.make({
path: "info.json",
})
.then(fs.read.json)
.then(sd => console.log("+", "ok", sd.json))
fs.read.json
-- magic JSON readingThis will work with .csv
, .txt
and .yaml
files, as
well as "-" for stdin.
You must independently install js-yaml
and/or csvtojson
according to your needs.
fs.read.utf8
- read UTF-8 document_.promise.make({
path: "doc.txt",
})
.then(fs.read.utf8)
.then(sd => console.log("+", "ok", sd.document_media_type, sd.document))
fs.read.stdin
- read stdinfs.write
fs.write.utf8
: write UTF-8 document_.promise.make({
path: "write.txt",
document: "Hello, world / 你好,世界\n",
})
.then(fs.make.directory.parent)
.then(fs.write.utf8)
.then(sd => console.log("+", "ok", sd.path))
fs.write.buffer
: write Buffer_.promise.make({
path: "write.txt",
document: Buffer.from("Hello, world / 你好,世界\n", "utf-8"),
})
.then(fs.make.directory.parent)
.then(fs.write.buffer)
.then(sd => console.log("+", "ok", sd.path))
fs.remove
: remove fileNote that no error is reported if the file does not exist
fs.remove.directory
: remove directoryNote that no error is reported if the directory does not exist
fs.remove.recursive
: remove a bunch off stuffNOT IMPLEMENTED
fs.tmpfile
: make a temporary fileThe path of the file will be placed in self.path
.
The file will disappear when the process exits.
fs.truncate
: truncate a fileself.document_length
can be used to control
where the truncation happens
fs.exists
: does it exist?Test whether an object on the filesystem exists.
self.exists
will be set to true
or false
as appropriate
_.promise.make({
path: "doc.txt",
})
.then(fs.exists)
.then(sd => console.log("+", "ok", sd.path, sd.exists)
fs.is.*
: test file typeTest whether an object is of a certain type
self.exists
will be set to true
or false
as appropriate
fs.is.file
: is it a normal file typeNOT IMPLEMENTED YET
_.promise.make({
path: "doc.txt",
})
.then(fs.is.file)
.then(sd => console.log("+", "ok", sd.path, "is-file", sd.exists)
fs.is.file
: is it a normal file typeNOT IMPLEMENTED YET
_.promise.make({
path: ".",
})
.then(fs.is.directory)
.then(sd => console.log("+", "ok", sd.path, "is-directory", sd.exists)
fs.is.symbolic_link
: is it a symbolic linkNOT IMPLEMENTED YET
_.promise.make({
path: ".",
})
.then(fs.is.symbolic_link)
.then(sd => console.log("+", "ok", sd.path, "is-symbolic-link", sd.exists)
For security and efficiency reason, some code from third party modules has
been directly included in this module (in ./contrib
)
FAQs
POP file system operations
The npm package iotdb-fs receives a total of 64 weekly downloads. As such, iotdb-fs popularity was classified as not popular.
We found that iotdb-fs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.