npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

galactic-fs

v0.0.1

Published

Promise-based File Store API built on top of Fireproof.

Downloads

17

Readme

GalacticFS

Promise-based File Store API built on top of Fireproof.

Installation

npm install galactic-fs

Getting Started

Basic Usage

const fs = new GalacticFS('MyStorageId') // creates filestore with specified name

/* read entry(s) */
fs.read('/path/to/file')      // read file
fs.read('/path/to/folder/')   // read folder
fs.read('/path*')             // read all matches

/* write entry(s) */
fs.write('/path/to/file')           // create empty file
fs.write('/path/to/file', data)     // create file with content
fs.write('/path/to/folder/')        // create empty folder
fs.write('/path/to/folder/', data)  // create folder with content

/* copy entry(s) */
fs.copy('/path/from/file', '/path/to/file')       // copy file contents
fs.copy('/path/from/file', '/path/to/folder/')    // copy file into folder
fs.copy('/path/from/folder/', '/path/to/folder/') // copy folder contents
fs.copy('/path*', '/path/to/folder/')             // copy all matches into folder

/* move entry(s) and delete original(s) */
fs.move('/path/from/file', '/path/to/file')       // move file contents
fs.move('/path/from/file', '/path/to/folder/')    // move file into folder
fs.move('/path/from/folder/', '/path/to/folder/') // move folder contents
fs.move('/path*', '/path/to/folder/')             // move all matches into folder

/* delete entry(s) */
fs.delete('/path/to/file')     // delete file
fs.delete('/path/to/folder/')  // delete folder and its content
fs.delete('/path*')            // delete all matches

Advanced Usage

fs.{state}

fs.supported  // local filestore is supported by device [boolean readonly]
fs.persistent // local filestore is persistent [boolean readonly]
fs.syncable   // local filestore can sync to remote [boolean readonly]
fs.writeable  // local filestore is writable [boolean readonly]

fs.info

const info = await fs.info()
console.log(info.freespace)  // available space
console.log(info.quota)      // storage quota
console.log(info.used)       // used space

fs.read

/* read single file with options */
const file = await fs.read({
    path: '/path/to/file',  // required
    as: 'blob'  // 'arrayBuffer' | 'blob' | 'json' | 'url' | 'string'
})

/* read folder with options */
const folder = await fs.read({
    path: '/path/to/folder/',  // required
    depth: 3,  // how deep to traverse
    as: 'blob',  // format for file contents
    filter: file => file.name.endsWith('s'),  // filter entries
    sort: (a, b) => a.size - b.size  // sort entries
})

fs.write

/* file operations */
await fs.write('/path/to/file', 'Hello World', {
    append: false,    // append instead of overwrite
    overwrite: true   // allow overwriting existing
})

/* folder operations */
await fs.write('/path/to/folder/', {
    overwrite: true  // allow overwriting existing
})

/* batch operations */
await fs.write('/path/to/folder/', {
    'file1.txt': 'content1',
    'file2.txt': 'content2'
}, {
    append: false,
    overwrite: true
})

fs.copy and fs.move

/* copy with options */
await fs.copy({
    from: '/source/folder/',
    to: '/dest/folder/',
    append: false,
    overwrite: true
})

/* move with options */
await fs.move({
    from: '/source/folder/',
    to: '/dest/folder/',
    append: false,
    overwrite: true
})

Working with Files and Folders

File Objects

file.isFolder   // always false
file.isFile     // always true
file.path       // full path to file
file.name       // file name
file.size       // size in bytes
file.type       // mimetype

// Get file contents in different formats
await file.as('entry')       // returns self
await file.as('blob')        // as blob
await file.as('json')        // as json
await file.as('string')      // as string
await file.as('arrayBuffer') // as arrayBuffer
await file.as('url')         // as url

Folder Objects

folder.isFolder  // always true
folder.isFile    // always false
folder.path      // full path
folder.name      // folder name

// Folder operations
await folder.read('subpath/subfile')       // read relative path
await folder.write('subpath/subfile', data)   // write to relative path

// Get folder contents
await folder.as('entry', 'array') // as array
await folder.as('entry', 'tree')  // as tree structure

// Process contents
await folder.forEach(async file => {
    const data = await file.as()
    // process data
})

Content Structures

// Array format (folder.as('entry', 'array'))
const array = [
    file1,
    folder1,
    file2,
    // ...
]

// Tree format (folder.as('entry', 'tree'))
const tree = {
    'file1.txt': file1,
    'folder1': {
        'file2.txt': file2,
        // ...
    }
}

Error Handling

All async operations throw standard Error objects:

try {
    await fs.read('/nonexistent')
} catch (error) {
    console.error('File not found:', error.message)
}