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

node-swiftclient

v1.2.0

Published

A Node.js client library for interacting with OpenStack Swift Object Storage

Downloads

771

Readme

Openstack Swift Client Library for Node.js

A Node.js client library for interacting with OpenStack Swift Object Storage. This library provides robust functionality for managing containers and objects, offering a clean and straightforward API for common Swift operations. It supports all Swift authentication versions (v1.0, v2.0, and v3).

Installation

Install the library using npm/pnpm:

npm install node-swiftclient

or

yarn install node-swiftclient

Quick Example

How to create a container, upload a file, and list objects:

import { SwiftClient } from 'node-swiftclient';
import { Readable } from 'stream';

async function example() {
  // Initialize SwiftClient
  const client = new SwiftClient({
    authVersion: 3,
    authUrl: 'https://auth.example.com/v3',
    userName: 'demo',
    apiKey: 'demo',
    tenant: 'test',
    tenantDomain: 'Default',
    domain: 'Default',
  });

  // Create a container
  await client.createContainer('my-container', true, {
    'X-Meta-Info': 'example',
  });

  // List containers
  const containers = await client.listAllContainers();
  console.log('Containers:', containers);

  // Upload an object as a stream
  const container = client.getContainer('my-container');
  const stream = Readable.from('Hello, Swift!');
  await container.putObject('docs/hello.txt', stream);

  //List all object in pseudo-folder 'img'
  const objects = container.listObjects({ prefix: 'docs/' });
  console.log(objects);

  // Download the object as a buffer
  const buffer = await container.getObjectAsBuffer('docs/hello.txt');
  console.log('Downloaded Content:', buffer.toString());

  // Clean up: Delete the object and container
  await container.deleteObject('docs/hello.txt');
  await client.deleteContainer('my-container');
}

Key Features

  • Container Management: Create, delete, and list containers.
  • Object Management: Upload, download, delete, and list objects in containers.
  • Metadata: Set and retrieve metadata for containers and objects.
  • Authentication: Supports Swift authentication versions 1.0, 2.0, and 3.

API Documentation

SwiftClient

| Method | Description | | --------------------- | ------------------------------------------------------------------------ | | createContainer() | Creates a new container with optional metadata and headers. | | getContainer() | Retrieves a SwiftContainer object for managing objects in a container. | | listAllContainers() | Lists all containers with optional filters and headers. | | deleteContainer() | Deletes a container. | | getClientInfo() | Retrieves information about the authenticated Swift client. | | getContainerMeta() | Retrieves metadata for the specified container. |


SwiftContainer

| Method | Description | | --------------------- | ----------------------------------------------------------------------------- | | listObjects() | Lists objects in the container with optional filtering and pagination. | | listObjectFolders() | Lists object folders (subdirectories) with optional filtering and pagination. | | iterateObjects() | Iterates over all objects in the container in batches. | | getObjectMeta() | Retrieves metadata for a specific object. | | patchObjectMeta() | Updates metadata for a specific object. | | putObject() | Uploads an object to the container from a stream or buffer. | | deleteObject() | Deletes a specific object from the container. | | getObject() | Downloads a specific object as a readable stream. | | getObjectInfo() | Retrieves information about an object without downloading its content. | | getObjectAsBuffer() | Downloads a specific object as a buffer. |

Example Usage

import { SwiftContainer } from './swift-container';

async function main(container: SwiftContainer) {
  // List objects in the container
  const objects = await container.listObjects({ prefix: 'folder/' });
  console.log('Objects:', objects);

  // Upload an object
  await container.putObject('example.txt', Buffer.from('Hello, world!'));

  // Retrieve metadata for an object
  const metadata = await container.getObjectMeta('example.txt');
  console.log('Metadata:', metadata);

  // Delete an object
  await container.deleteObject('example.txt');
}

Configuration

SwiftClient supports multiple authentication methods. Examples:

Auth Version 1

swift = new SwiftClient({
  authVersion: 1,
  authUrl: 'http://example.com/auth/v1.0',
  userName: 'tester2',
  password: 'testing2',
  tenant: 'test2',
});

Auth Version 2

Note: Version 2 is deprecated and you should upgrade your swift storage.

swift = new SwiftClient({
  authVersion: 2,
  authUrl: 'http://auth.example.com/v2.0',
  userName: 'demo',
  apiKey: 'demo',
  tenant: 'test',
});

Auth Version 3

swift = new SwiftClient({
  authVersion: 3,
  authUrl: 'http://auth.example.com/v3',
  userName: 'demo',
  apiKey: 'demo',
  tenant: 'test',
  tenantDomain: 'Default',
  domain: 'Default',
});

License

This library is licensed under the MIT License.