@snap-fileio/extension
snap-fileio / extension
This is the Snap! File I/O Extension, a loadable JavaScript extension for the Snap! visual programming environment that enables Snap! programs to read and write files on the local filesystem via a Node.js middleware server.
The extension registers 13 primitives (8 plain-text, 4 structured data, 1 error reporter) and injects a "Files" block category ("Dateien" in German) into the Snap! palette. It communicates with the middleware over HTTP REST, targeting any server that implements the API contract.
The extension is consumed by snap-out, which provides the Electron shell, Express server, and workspace configuration.
Blocks
Block text below is quoted verbatim from src/blocks.xml;
treat that file as authoritative if this table ever drifts.
Commands
| Block | Description |
|---|---|
write %'content' to file %'path' |
Create or overwrite a text file |
append %'content' to file %'path' |
Append text to a file |
delete file %'path' |
Delete a file |
create directory %'path' |
Create a directory |
write CSV %'data' to file %'path' %'delim' |
Write list-of-lists as CSV; delimiter is an optional expandable input, default ; |
write JSON %'data' to file %'path' |
Write Snap! data as JSON |
Reporters
| Block | Returns |
|---|---|
read file %'path' |
String |
read lines of file %'path' |
List of strings |
list files in %'path' |
List of entry names |
file %'path' exists? |
Boolean |
read CSV file %'path' %'delim' |
List of lists; delimiter is an optional expandable input, default auto-detect |
read JSON file %'path' |
Snap! data (objects as list-of-pairs) |
last file I/O error |
Error message string, or empty |
Building
The extension is bundled into a single IIFE file for browser loading:
npm run build
Output: dist/snap-fileio-extension.js
Testing
npm test
License
The Snap! File I/O extension is free software. You may redistribute and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.