Save file dialog in browser, write file to disk in node

Downloads in past


42142.3.15 years ago8 years agoMinified + gzip package size for save-file in KB


save-file unstable Build Status Greenkeeper badge
Save file in node/browser. In browser it prompts save file dialog, in node it creates a file.
  • Provides common interface for both node/browser.
  • Fixes dialog race in browser − when multiple save-files are called at the same time.
  • Handles any types of input data − Buffer, ArrayBuffer, ArrayBufferView, File, Blob, data-uri string, ImageData etc.


npm install save-file ```js // const save = require('save-file') import { save } from 'save-file' await save(data, 'example.mp3') const saveSync = require('save-file/sync') saveSync(otherData, 'example2.mp3') ```


await save(data|filename, filename|data)

Save data source to the filename destination, return actual saved ArrayBuffer. saveSync performs synchronous call. data type can be:
  • Buffer, ArrayBuffer
  • File, Blob
  • dataURI, base64 string
  • TypedArray, Array
  • ImageData, AudioBuffer
  • Object
  • etc.
See to-array-buffer for the full list. The data is expected to be encoded to target format, for that purpose see image-encode, audio-encode etc. Mime type is detected from the file extension/data type automatically.

Credits & related

  • file-saver − create download file dialog in browser.
  • write − write file in node, create directories if none.


© Dmitry Yv 2018. MIT Licensed.