Big update!Announcing Socket for GitHub 1.0. Learn more
Socket
BlogLoveFAQ
Install
Log in

clone-response

Package Overview
Dependencies
1
Maintainers
2
Versions
11
Issues
File Explorer

Advanced tools

clone-response

Clone a Node.js HTTP response stream

    2.0.0latest

Version published
Maintainers
2
Weekly downloads
11,554,437
decreased by-4.67%

Weekly downloads

Changelog

Source

Breaking

  • Require Node.js 14 2d4ccff
  • This package is now pure ESM. Please read this.

https://github.com/sindresorhus/clone-response/compare/v1.0.2...v2.0.0

Readme

Source

clone-response

Clone a Node.js HTTP response stream

Returns a new stream and copies over all properties and methods from the original response giving you a complete duplicate.

This is useful in situations where you need to consume the response stream but also want to pass an unconsumed stream somewhere else to be consumed later.

Install

npm install clone-response

Usage

import http from 'node:http'; import cloneResponse from 'clone-response'; http.get('http://example.com', response => { const clonedResponse = cloneResponse(response); response.pipe(process.stdout); setImmediate(() => { // The response stream has already been consumed by the time this executes, // however the cloned response stream is still available. doSomethingWithResponse(clonedResponse); }); });

Please bear in mind that the process of cloning a stream consumes it. However, you can consume a stream multiple times in the same tick, therefore allowing you to create multiple clones. For example:

const clone1 = cloneResponse(response); const clone2 = cloneResponse(response); // The response can still be consumed in this tick but cannot be consumed if passed // into any async callbacks. clone1 and clone2 can be passed around and be // consumed in the future.

API

cloneResponse(response)

Returns a clone of the passed in response stream.

response

Type: Stream

A Node.js HTTP response stream to clone.

Keywords

FAQs

What is clone-response?

Clone a Node.js HTTP response stream

Is clone-response popular?

The npm package clone-response receives a total of 9,278,655 weekly downloads. As such, clone-response popularity was classified as popular.

Is clone-response well maintained?

We found that clone-response demonstrated a healthy version release cadence and project activity. It has 2 open source maintainers collaborating on the project.

Last updated on 17 Jul 2022
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc