npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

html5-file-js

v1.4.1

Published

async HTML5 File object operating tool

Downloads

74

Readme

html5-file-js

an HTML5 File operating tool which could read from a File or Blob, or write data into a File.

Installation

npm

npm install html5-file-js

browser

<script type="text/javascript" src="path-to/html5-file-js.js"></script>

Usage

ES6 import

import FileJS from 'html5-file-js'

CommonJS

const FileJS = require('html5-file-js') 

Without RequireJS

not supported under current version

Read

readFile(file: File, callback: Function, options: Object)

read a whole File or Blob into String or ArrayBuffer

file: an HTML5 File object or a Blob

options:

{
    type: 'text', 'buffer' or 'binaryString'
    encoding: encoding of the text, required if type is 'text'
    bufferType: type of the typedArray of the ArrayBuffer, required if type is 'arrayBuffer', return ArrayBuffer if not provided
}

callback: function(err, data) err: an DOMException, null if no err occured data: read Data

var file = new File("1")

FileJS.readFile(file, (err, data) => {
    console.log(data)
}, {
    type: FileJS.types.READ_AS_TEXT
})
readFileProm(file: File, options: Object)

a promisified readFile function

var file = new File("1")

FileJS.readFileProm(file, {
    type: FileJS.types.READ_AS_TEXT
}).then((data) => {
    console.log(data)
}, (err) => {
    ...
})
readChucks(file: File, callback: Function, options: Object)

chained reading operation of a File or Blob, each run a user defined size of chuck is read and wait to be processed

file: an HTML5 File object or a Blob

options:

{
    chuckSize: size(KB) of chucks read each run
    type: 'text', 'buffer' or 'binaryString'
    encoding: encoding of the text, required if type is 'text'
    bufferType: type of the typedArray of the ArrayBuffer, required if
        type is 'arrayBuffer', return ArrayBuffer if not provided
}

callback: function(err, data, loaded, progress) err: an DOMException, null if no err occured data: read Data loaded: currently loaded size(byte) progress: current reading progress(1-100)

var file = new File(["1"], '1')

FileJS.readChucks(file, (err, data, loaded, progress) => {
    console.log(data)
    console.log(loaded)
    console.log(progress)
}, {
    type: FileJS.types.READ_AS_TEXT,
    chuckSize: 1
})
readChucksProm(file: File, callback: Function, options: Object)

a promisified readChucks function

callback: function(err, data, loaded, progress) data: read Data loaded: currently loaded size(byte) progress: current reading progress(1-100)

var file = new File(["1"], '1')

FileJS.readChucksProm(file, (data, loaded, progress) => {
    console.log(data)
    console.log(loaded)
    console.log(progress)
}, {
    type: FileJS.types.READ_AS_TEXT,
    chuckSize: 1
}).then(() => {
    ...
}, (err) => {
    ...
})

Write

writeFile(file: File|String, data: String|ArrayBuffer, callback: Function, options: Object)

write data into a File this operation doesn't alter the original file, but create a new File

if file is a string, it's taken as the filename of the new file if the file is not provided, create a new file with data if the file is provided, append data to the file

file: an HTML5 File object or a Blob | fileName string

data: data to write into the File object, String or ArrayBuffer

options:

{
    encoding: encoding of the text, required if data is String
    name: fileName string
    mimeType: mimeType of the file created, 
        use the original file's mimeType if not provided,
        if there is no original file, set to ""
}

callback: function(err, data, loaded, progress) err: an DOMException, null if no err occured file: file created

var file = new File(["1"], '1')

FileJS.writeFile(file, "2", (err, file) => {
    console.log(file)
}, {
    name: "filename"
})

FileJS.writeFile("filename","2", (err, file) => {
    console.log(file)
})

FileJS.writeFile("2", (err, file) => {
    console.log(file)
}, {
    name: "filename"
})
writeFileProm(file: File|String, data: String|ArrayBuffer, options: Object)

a promisified writeFile

var file = new File(["1"], '1')

FileJS.writeFile(file, "2" {
    name: "filename"
}).then((file) => {
    console.log(file)
}, (err) => {
    ...
})

FileJS.writeFile("filename","2" {}).then((file) => {
    console.log(file)
}, (err) => {
    ...
})

FileJS.writeFile("2" {
    name: "filename"
}).then((file) => {
    console.log(file)
}, (err) => {
    ...
})
rename(file: File, filename: String)

change the name of a file

Crypto

encription and decription are supported after version 1.1.* these operations are based on implementations of crypto-browserify

encriptFile(file: File, callback: Function, options: Object)

encript the given file using a certain algrithm which is dependent on OpenSSL the encript operation is based on crypto-borwserify this operation is chained, so you could provide chuckSize in options

  {
      chuckSize: size(KB) of chucks read each run
      name: user defined name of the written file
      algrithm: an string refering to the encription algrithm, fro example: aes256 aes128 aes-128-cbc aes-128-gcm
      key: 
      iv:
  }
callback takes data, loaded, progress as params

``` this function returns promise whose value is the encripted file
var file = new File(["1"], '1')
FileJS.encriptFile(file, (data, loaded, progress)=> {
    console.log(progress)
}, {
    name: 'encriptedFile',
    altrithm:  'aes-128-cbc',
    key:  'a secrect',
    iv: 'iv' //must be 16 bit
}).then(encriptedFile => {
    ...
})
decriptFile(file: File, algrithm: String, key: ArrayBuffer|String, callback: Function, options: Object)

decript the given file using a certain algrithm which is dependent on OpenSSL the decript operation is based on crypto-borwserify this operation is chained, so you could provide chuckSize in options

  {
      chuckSize: size(KB) of chucks read each run
      name: user defined name of the written file
      algrithm: an string refering to the encription algrithm, fro example: aes256 aes128 aes-128-cbc aes-128-gcm
      key: 
      iv:
  }
callback takes data, loaded, progress as params

``` this function returns promise whose value is the encripted file
FileJS.decriptFile(encriptedFile, (data, loaded, progress)=> {
    console.log(progress)
}, {
    name: 'decriptedFile',
    altrithm:  'aes-128-cbc',
    key:  'a secrect',
    iv: 'iv' //must be 16 bit
}).then(decriptedFile => {
    ...
})