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

@e3o/gcp-storage

v1.0.2

Published

Provides a storage handling solution.

Downloads

27

Readme

storage

This modules provides methods manage object storage in Google Cloud Storage.

How to use

Import

import { FileStorage } from 'storage'

Init

First, we need an instance of FileStorage

export const fileStorage = new FileStorage({
  bucket: 'BUCKET_NAME',
  keyFilename: 'STORAGE_KEY_FILENAME',
})
  • STORAGE_KEY_FILENAME is the credential file URI

Upload file

Upload a file to the remote storage.

const fileName = await fileStorage.upload(
        {
            pathDestination: 'path',
            fileName: 'testFile',
            file: Buffer.from('Test content', 'utf-8'),
            contentType: "text/plain"
            metadata: { something: 'here' }
        }
)

// fileName -> path/testFile
// OR
const fileName = await fileStorage.send(
        {
            pathDestination: 'path',
            fileName: 'testFile',
            file: fs.createReadStream('./test.png'),
            contentType: "img/png"
            metadata: { something: 'here' }
        }
)

// fileName -> path/testFile
  • The file attribute MUST be a Buffer or a ReadableStream.
  • The contentType attribute is not required default to "application/octet-stream"
  • The metadata object is not required. Values are converted to string

Download file

Download a file from the bucket

const fileBuffer = await fileStorage.download(fileName)
  • fileName is the string returned by the upload() method

Misc

getMetadata

Get the global metadata of an object

const metadata = await fileStorage.getMetadata(fileName)

/*
metadata ->
{ kind: 'storage#object',
  id: 'sandbox',
  selfLink:
   'https://www.googleapis.com/storage/v1/b/BUCKET_NAME/o/path%2FtestFile',
  name: 'path/testFile',
  bucket: 'BUCKET_NAME',
  generation: '123456789',
  metageneration: '1',
  contentType: 'application/octet-stream',
  storageClass: 'STANDARD',
  size: '12',
  md5Hash: 'MD5_HASH',
  mediaLink:
   'https://storage.googleapis.com/download/storage/v1/b/BUCKET_NAME/o/path%2FtestFile?generation=123456789&alt=media',
  cacheControl: 'public, max-age=31536000',
  crc32c: 'r5b9xg==',
  etag: 'CJD+6K2xsuUCEAE=',
  timeCreated: '2019-10-23T12:30:40.811Z',
  updated: '2019-10-23T12:30:40.811Z',
  timeStorageClassUpdated: '2019-10-23T12:30:40.811Z'
  metadata: { something: 'here', type: 'text' }
}

*/
  • fileName is the string returned by the upload() method