Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mangosteen/got-to-temp

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mangosteen/got-to-temp

Download HTTP streams to temp files.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

got-to-temp

First, use Got to create retryable read stream.

@mangosteen/got-to-temp then helps you to:

  • Automatically retry on failures
  • Stream Got response data to a temp file that is automatically created for you
  • Optionally, use transform streams to modify the stream data on-the-fly

If there are any failures during download, the temp file is automatically cleaned up.

If there are any errors during download and Got ran out of retries, the error is propagated via rejected promise.

Installation

With npm do:

$ npm install @mangosteen/got-to-temp

Usage

import { downloadToTempFile } from '@mangosteen/got-to-temp';
import { DigestStream } from '@mangosteen/digest-stream';
import got from 'got';
import crypto from 'crypto';

(async () => {
    // Setup Got with retry
    const gotClient = got.extend({
        retry: {
            limit: 5,
        },
    });

    // If Got runs out of retries, this promise will reject with Got error
    const downloadResult = await downloadToTempFile(
        // Factory method to create download stream
        () => gotClient.stream.get('https://nodejs.org/dist/v14.17.5/node-v14.17.5.tar.gz'),
        // Optional factory method to create transform streams
        () => [
            // We use digest as an example here to show how to compute SHA-256 while
            // the file is being downloaded. You may use any other transform streams,
            // or simply avoid passing this factory method altogether.
            new DigestStream({
                digest: crypto.createHash('sha256'),
            }),
        ] as const,
    );

    // Path to a file in a temp directory containing the downloaded data
    console.log(downloadResult.filePath);

    // Access the transform stream instances used during download
    console.log(
        downloadResult.transforms[0].digest().toString('hex'),
    );
})();

Keywords

FAQs

Package last updated on 22 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc