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

@muddykat-tech/file-interface

v3.0.2

Published

Client request library interface and explorer

Downloads

7

Readme

File Interface

Client request library interface and explorer

build status npm version

About

Reading, writing and exploring file systems within Buttercup has typically been a complex process with differing approaches on the different application platforms. This library is intended to provide a common API with which to build the following tools:

  • File explorer interface (between client and UI)
  • File creation (new vault feature)
  • File selection (UI, returing identifier)

The API provided by this library is common across all data providers:

None of these packages are included in this repository and are expected to be provided at runtime.

To create each of the interfaces, run the following:

import { instantiateInterface } from "@buttercup/file-interface";

const fsInterface = instantiateInterface("fs", { fs });
const googleDriveInterface = instantiateInterface("googledrive", { googleDriveClient });
const dropboxInterface = instantiateInterface("dropbox", { dropboxClient });
const webdavInterface = instantiateInterface("webdav", { webdavClient });

Installation

Install by running: npm install @buttercup/file-interface --save

Environment support

This library supports NodeJS version 16 and above. It is full ESM and therefore requires an environment which supports ECMAScript modules.

Usage

An interface is created when required, once you have the necessary components for the interface to function:

import { instantiateInterface } from "@buttercup/file-interface";
import fs from "fs";

const fsInterface = instantiateInterface("fs", { fs });
fsInterface.getDirectoryContents({ identifier: "./dirname" }).then(results => {
    // Returns something like the following:
    // [{
    //     identifier: "/root/dirname/testfile.txt",
    //     name: "testfile.txt",
    //     type: "file",
    //     size: 231,
    //     created: "Mon, 10 Oct 2011 23:24:11 GMT",
    //     modified: "Mon, 11 Oct 2011 10:57:44 GMT"
    // }]
});

You'll notice a lot of identifier usage when calling methods provided by this library. As some remote systems require more information, the API for this project uses identifier objects (parent and file) to collect information that better describes remote objects in enough detail to be usable across file systems. Google Drive, for example, doesn't use typical paths - instead files and directories are referred to by IDs:

import { instantiateInterface } from "@buttercup/file-interface";
import { createClient } from "@buttercup/googledrive-client";

const googleDriveClient = createClient(myToken);
const fsInterface = instantiateInterface("googledrive", { googleDriveClient });

fsInterface.getDirectoryContents({ identifier: "<dir-id>" }).then(results => {
    // Returns something like the following:
    // [{
    //     identifier: "0BxOS7mTBMR_bMHZRUjJ5NU1ZOWs",
    //     name: "testfile.txt",
    //     type: "file",
    //     size: 231,
    //     created: "Mon, 10 Oct 2011 23:24:11 GMT",
    //     modified: "Mon, 11 Oct 2011 10:57:44 GMT"
    // }]
});

// Update existing file
fsInterface.putFileContents(
    { identifier: "<dir-id>" },
    { identifier: "0BxOS7mTBMR_bMHZRUjJ5NU1ZOWs", name: "testfile.txt" },
    "some data"
);

// Write new file
fsInterface.putFileContents(
    { identifier: "<dir-id>" },
    { identifier: null, name: "newfile.txt" },
    "some data"
).then(result => {
    // `result` is like:
    // {
    //     identifier: "0BxOS7mTBMR_bMHZRUjJ5NU1ZOWs",
    //     name: "newfile.txt"
    // }
});

Supported fields

When calling getDirectoryContents, some base fields are always available:

  • identifier: The identifying path or ID of the file/directory
  • filename: The base filename of the file/directory
  • type: Either "file" or "directory"
  • size: The size, in bytes, of the item (always 0 for directories)

Other additional fields are sometimes returned, based upon what the remote system supports. These can be detected by calling the getSupportedFeatures method on the interface instance. It returns an array of strings that indicate what is specified on each returned file item:

  • created indicates that a field called created is present on every file item, which is the creation date of the file.
  • modified indicates that a field called modified is present on every file item, which is the modification date of the file.
  • mime indicates that a field called mime is present on each file item, containing the MIME type of the item.