Socket
Socket
Sign inDemoInstall

streamsaver

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.3 to 2.0.4

.github/FUNDING.yml

2

package.json
{
"name": "streamsaver",
"version": "2.0.3",
"version": "2.0.4",
"description": "StreamSaver writes stream to the filesystem directly - asynchronous",

@@ -5,0 +5,0 @@ "main": "StreamSaver.js",

@@ -24,7 +24,7 @@ StreamSaver.js

<script src="https://cdn.jsdelivr.net/npm/web-streams-polyfill@2.0.2/dist/ponyfill.min.js"></script>
<script src="StreamSaver.js"></script>
<script src="https://cdn.jsdelivr.net/npm/streamsaver@2.0.3/StreamSaver.min.js"></script>
<script>
import streamSaver from 'StreamSaver'
const streamSaver = require('StreamSaver')
const streamSaver = window.streamSaver
import streamSaver from 'streamsaver'
const streamSaver = require('streamsaver')
const streamSaver = window.streamSaver
</script>

@@ -46,4 +46,2 @@ <script>

There a some settings you can apply to StreamSaver to configure what it should use
## Best practice

@@ -58,4 +56,6 @@

**Handle unload event** when user leaves the page. The download gets broken when you leave the page.
Because it looks like a regular native download process some might think that it's okey to leave the page beforehand since it's is downloading in the background directly from some a server, but it isn't.
```js
// abort so it dose not look stuck
window.onunload = () => {

@@ -75,3 +75,6 @@ writableStream.abort()

# Configuration
There a some few settings you can apply to StreamSaver to configure what it should use
```js

@@ -102,5 +105,5 @@ // StreamSaver can detect and use the Ponyfill that is loaded from the cdn.

How dose it work?
How does it work?
=====================
There is no magical `saveAs()` function that saves a stream, file or blob.
There is no magical `saveAs()` function that saves a stream, file or blob. (at least not if/when native-filesystem api becomes avalible)
The way we mostly save Blobs/Files today is with the help of [Object URLs](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL) and [`a[download]`][5] attribute

@@ -116,4 +119,4 @@ [FileSaver.js][2] takes advantage of this and create a convenient `saveAs(blob, filename)`. fantastic! But you can't create a objectUrl from a stream and attach

So the one and only other solution is to do what the server does: Send a stream
with Content-Disposition header to tell the browser to save the file.
But we don't have a server! So the solution is to create a service worker
with `Content-Disposition` header to tell the browser to save the file.
But we don't have a server or the content isn't on a server! So the solution is to create a service worker
that can intercept request and use [respondWith()][4] and act as a server.<br>

@@ -120,0 +123,0 @@ But a service workers are only allowed in secure contexts and it requires some effort to put up. Most of the time you are working in the main thread and the service worker are only alive for < 5 minutes before it goes idle.<br>

@@ -17,3 +17,4 @@ /* global chrome location ReadableStream define MessageChannel TransformStream */

const isSecureContext = window.isSecureContext
let useBlobFallback = /constructor/i.test(window.HTMLElement) || !!window.safari
// TODO: Must come up with a real detection test (#69)
let useBlobFallback = /constructor/i.test(window.HTMLElement) || !!window.safari || !!window.WebKitPoint
const downloadStrategy = isSecureContext || 'MozAppearance' in document.documentElement.style

@@ -136,2 +137,7 @@ ? 'iframe'

let bytesWritten = 0 // by StreamSaver.js (not the service worker)
let downloadUrl = null
let channel = null
let ts = null
// normalize arguments

@@ -153,6 +159,4 @@ if (Number.isFinite(options)) {

var bytesWritten = 0 // by StreamSaver.js (not the service worker)
var downloadUrl = null
var channel = new MessageChannel()
channel = new MessageChannel()
// Make filename RFC5987 compatible

@@ -196,3 +200,3 @@ filename = encodeURIComponent(filename.replace(/\//g, ':'))

}
var ts = new streamSaver.TransformStream(
ts = new streamSaver.TransformStream(
transformer,

@@ -199,0 +203,0 @@ opts.writableStrategy,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc