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

pipe-to-storage

v0.10.1

Published

Saves stuff (strings, readable streams, functions yielding readable streams) in a Google Storage bucket, with less typing. Handles retries, mime-types for you. Returns Promise

Downloads

42

Readme

pipe-to-storage

Build Status Known Vulnerabilities Language grade: JavaScript Total alerts

Importing and Setup

On Google platforms:

// storage version 2.x

const {Storage} = require('@google-cloud/storage');
const storage = new Storage();

// storage version 1.x

const storage = require('@google-cloud/storage')(); // storage 1.x

On other platforms: set up your API key, see relevant docs

Pass the storage object when setting up pipeToStorage for usage

const pipeToStorage = require('pipe-to-storage')(storage);

Usage

pipeToStorage(source, bucketName, fileName , optional )
.then(function(what){ 
   console.log("hooray! I wrote "+what.file+" to bucket "+what.bucket+" and it should have md5 "+what.md5);
 })
 .catch(function(e){
   console.log("oh no! an error occurred. here it is:");
   console.log(e);
 });

source must be either:

  • a string, which will be sent as-is to the new file [retry will use the same string]
  • a function that returns a readable stream [retry will call the function to get a fresh readable stream]
  • a readable stream [can not retry]

npm:promise-retry will be used to retry failed storage promises in the first two cases. A retry strategy is used that is appropriate for a cloud back-end environment: up to 3 retries per call within 30 seconds, then fail.

bucketname and filename are the Google Cloud Storage[tm] bucket and file names. gs:// is not needed in bucketName

optional is optional and may be:

  • absent or undefined -- pipeToStorage should try to look up the content-type from the fileName extension
  • the string 'json' -- shorthand to set metadata content-type: application/json
  • other strings -- sets the metadata content-type manually
  • an object, to set any writeStream.options in the internal storage createWriteStream call

returns a Promise that resolves to {bucket, file, md5, length} after saving the contents of source to storage.bucket(bucketName).file(fileName) or rejects with any errors not caught in retrys

md5 is in base64

Tests

This module is tested on Travis CI, but you won't be able to run the same tests yourself without some adjustments.

To run the tests in your own environment, change the storage API credentials (projectId, keyFilename) and the bucket name referenced in ./test/index.js.

Copyright

Copyright 2017 Paul Brewer, Economic and Financial Technology Consulting LLC [email protected]

License

The MIT License

No relationship to Google, Inc.

This is third party software, not a product of Google Inc.

The author(s) have no relationship to Google, Inc.