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

@vtfk/azure-blob-client

v0.1.6

Published

A client for working with Azure storage blobs

Downloads

24

Readme

azure-blob-client

An convenient library for working with Azure storage blobs

Get started

  1. Install
npm i @vtfk/azure-blob-client
  1. Setup environment variables (Not required)

| Name | Example | |---|---| |AZURE_BLOB_CONNECTIONSTRING| DefaultEndpointsProtocol=https;AccountName=[AccountName];AccountKey=[AccountKey];EndpointSuffix=core.windows.net | AZURE_BLOB_CONTAINERNAME | Blobs |

Import the package

const blobClient = require('@vtfk/azure-blob-client');
// OR just require the functions you need with destructoring
const { list, get, create, remove } = require('@vtfk/azure-blob-client'); 

Functions & examples

Save

Saves content to a given path

// Create a blob with path test.txt
await blobClient.save('test.txt', 'testdata');
await blobClient.save('test/test2.txt', 'data:plain/text;utf-8,test2');
await blobClient.save('test/folder1/test3.txt', 'data:plain/text;utf-8,test3');

We recommend using the dataUrl-format for storing data as it makes it easier to work with after it is retreived. Example: img-tags in HTML can display them as pictures and browsers can easily handle and download them.

If stored in dataUrl format the MIME type and encoding will be parsed when retreiving the data.

List

List one or more blobs matching the provided path

// Gets all blobs that has a path that starts with test
await blobClient.list('test');

// Gets all blobs in container
await blobClient.list('*');

// Yields
[
  {
    name: 'test.txt',
    path: 'test.txt',
    blobType: 'BlockBlob',
    createdOn: 2021-12-17T13:42:43.000Z,
    lastModified: 2021-12-17T13:46:18.000Z,
    lastAccessedOn: undefined
  },
  {
    name: 'test2.txt',
    path: 'test/test2.txt',
    blobType: 'BlockBlob',
    createdOn: 2021-12-17T13:42:43.000Z,
    lastModified: 2021-12-17T13:46:18.000Z,
    lastAccessedOn: undefined
  },
  {
    name: 'test3.txt',,
    path: 'test/folder1/test3.txt',
    blobType: 'BlockBlob',
    createdOn: 2021-12-17T13:42:43.000Z,
    lastModified: 2021-12-17T13:46:18.000Z,
    lastAccessedOn: undefined
  }
]

Get

Get one or more blobs with its data

// Gets a blob with name/path test.txt
await blobClient.get('test.txt')

// Yields
{
  name: 'test.txt',
  path: 'test.txt',
  extension: 'txt',
  data: 'testdata'
}
// Gets a blob with name/path test.txt
await blobClient.get('test/')

// Yields
[
  {
    name: 'test2.txt',
    path: 'test/test2.txt',
    extension: 'txt',
    type: 'plain/test',
    encoding: 'utf-8',
    data: 'data:plain/text;utf-8,test2'
  },
  {
    name: 'test3.txt',
    path: 'test/folder1/test3.txt',
    extension: 'txt',
    type: 'plain/test',
    encoding: 'utf-8',
    data: 'data:plain/text;utf-8,test3'
  }
]

Specify encoding of return value

If you for example need get to return base64 instead of a bufferstring, you can specify encoding in the options-parameter.

See valid encodings in NodeJs official documentation

// Gets a blob with name/path test.pdf and returns the content as a base64 string
await blobClient.get('test.pdf', { encoding: 'base64' })

// Yields
{
  name: 'test.pdf',
  path: 'test.pdf',
  extension: 'pdf',
  data: 'JVBERi0xLjQNCiX5+pr==....'
}

Remove

Removes one or more blobs patching the provided path

// Removes the blob with path test.txt
await blobClient.remove('test.txt');

// Yields
[ 'test.txt' ]
// Removes all blobs starting with test
await blobClient.remove('test');

// Yields
[ 'test/test2.txt', 'test/folder1/test3.txt' ]

createBlobServiceClient

Creates and returns a BlobServiceClient for working with lower-level API

// Create the client
const client = await blobClient.createBlobServiceClient();

createContainerClient

Creates and returns a ContainerClient for working with lower-level API

// Create the client
const client = await blobClient.createContainerClient();

Other

All functions takes in an optional options object

// Create the options object
const options = {
  connectionString: 'Azure storage account connection string',
  containerName: 'Azure storage account container name '
}
// Get blobs with provided options
await blobClient.get('test.txt', options);