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

solid-rest-file

v1.0.0

Published

treat a file system as a (very) minimal Solid REST server

Downloads

27

Readme

Solid REST file

treat a file system as a (very) minimal Solid server

NPM

Not implemented: OPTION and PATCH (and therefore rdflib's Updater).

Note: this library incorporates and extends Thomas Bergwinki's excellent file-fetch

Using this library with rdflib other Solid Tools

Although this library may be used stand-alone, it is meant primarily for use with other Solid tools. This library is included in solid-auth-cli, the nodejs auth/fetch library for Solid which is itself included in rdflib.js and solid-file-client and (soon) query-ldflex. When used with rdflib.js in nodejs context, it supports all fetcher methods (load, putBack, webOperation, etc.) on local files and folders.

Here's how to use this library with rdflib:

const $rdf = require('rdflib^0.20.0');
const auth = require('solid-auth-cli^0.2.0'); // includes solid-rest-file
const store = $rdf.graph();
const fetcher = $rdf.fetcher(store,{fetch:auth.fetch});
/*
  you can now use any rdflib methods excpet updater to 
  create, delete, access, and query file:// resources
  if you use auth.login, you can also move resources 
  between a remote Pod and your local file system.
*/

Requests

This library expects IRIs that start with "file://" and are followed by a full pathname. A file located at /home/me/somepath/somefile.txt would be requested like this:

file:///home/me/somepath/somefile.txt

Note the three slashes in the pathname.

A GET request uses fetch() with a single parameter: the pathname of the resource requested. The resource is returned as a readable stream which will be the contents of a file, or, if a Container is requested, the stream will be a Turtle representation of the Container including a list of the resources it contains.

const fetch = require("solid-rest-file");
const path  = require("path");
const file  = "file://"+ path.join(process.cwd(), "foo.txt");
fetch( file ).then( response => {
    if(response.ok) {
        response.text().then( txt => {
            console.log(txt)
        }, err => {"read error : "});
    }
    else {
        console.log( response.status, response.statusText );
    }
},err=>{"fetch error : "+err});

All other requests use fetch() with two parameters, the pathname and a set of options as specified in the Solid REST Specification. For example, to create a new Container at the location /somepath/morepath/newFolder

fetch( "file:///somepath/morepath", {
    "Method":"POST",
    headers: { 
        Link: '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"',
        "Content-Type": "text/turtle",
        Slug: newFolder
    }
}).then( ...

As per the spec, this will fail if the containing folder "/somepath/morepath" does not already exist. Use PUT to create a resource and its container. PUT on a Container by itself is not suppoted.

Responses

  • POST Container
    • 201 on success
    • 404 if the Container of the Container does not exist
    • returns created path in location header
  • POST Resource
    • 201 on success
    • 404 if the Container of the new Resource does not exist
    • returns created path in location header
  • PUT Resource
    • 201 on success
    • creates Container of the new Resource if it does not exist
    • returns created path in location header
  • PUT Container
    • 405 method not supported
  • GET Resource
    • 200 on success
    • 404 if not found
    • returns body of resource as a readable stream in response.body
    • returns content-type in header
    • returns .acl, .describedBy, and type Links in header
  • GET Container
    • 200 on success
    • 404 on not found
    • returns turtle representation of ldp:BasicContainer as readable stream
    • returns content-type in header
    • returns .acl, .describedBy, and type Links in header
  • HEAD Container
  • HEAD Resource
    • 200 on success
    • 404 on not found
    • returns .acl, .describedBy, and type Links in header
  • DELETE Resource
  • DELETE Container
    • 200 on success
    • 404 on not found
    • 409 on Container-not-empty or other failure
  • All other methods
    • 405 method not supported

copyright © 2019, Jeff Zucker, may be freely distributed with the MIT license