Giter Site home page Giter Site logo

save-file's Introduction

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.

Usage

npm install save-file

// 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')

API

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
  • ndarray
  • 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.
  • to-array-buffer — turn anything into ArrayBuffer.
  • simple-mime — tiny mime types detector.

Copyright

© Dmitry Yv 2018. MIT Licensed.

save-file's People

Contributors

dy avatar greenkeeper[bot] avatar pedro-vk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.