all da files

This commit is contained in:
jllord
2013-05-27 13:45:59 -07:00
commit 59d3d30afa
6704 changed files with 1954956 additions and 0 deletions

View File

@@ -0,0 +1 @@
node_modules

View File

@@ -0,0 +1,60 @@
# fileliststream
Given a FileList, turn it into a FileListStream.
# install
Use it with npm & [browserify](/substack/node-browserify)
```bash
$ npm install fileliststream
```
# example
```js
const FileListStream = require('fileliststream');
const body = document.body;
// make it so console can be piped to.
console.write = console.log;
function noop(event) {
event.preventDefault();
event.stopPropagation();
return false;
};
['dragenter',
'dragleave',
'dragexit',
'dragover'
].forEach(function (eventType) {
body.addEventListener(eventType, noop);
});
body.addEventListener('drop', function (event) {
event.stopPropagation();
event.preventDefault();
const fileList = FileListStream(event.dataTransfer.files);
fileList.files.map(function(file) {
file.pipe(console);
});
return false;
});
```
# usage
```js
FileListStream(fileList, [options])
```
`options` currently has one possible parameter, `output`. Possible values are:
* `binary` [default]
* `dataurl`
* `arraybuffer`
* `text`

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,5 @@
<html>
<body style="width: 100%; height: 100%; padding: 0; background: #aaf">
<script src='bundle.js'></script>
</body>
</html>

View File

@@ -0,0 +1,34 @@
const FileListStream = require('./');
const body = document.body;
// make it so console can be piped to.
console.write = console.log;
function noop(event) {
event.preventDefault();
event.stopPropagation();
return false;
};
['dragenter',
'dragleave',
'dragexit',
'dragover'
].forEach(function (eventType) {
body.addEventListener(eventType, noop);
});
body.addEventListener('drop', function (event) {
event.stopPropagation();
event.preventDefault();
const fileList = FileListStream(event.dataTransfer.files, {
output: 'text'
});
fileList.files.map(function(file) {
file.pipe(console);
});
return false;
});

View File

@@ -0,0 +1,54 @@
const Stream = require('stream');
function FileListStream(fileList, options) {
if (!(this instanceof FileListStream))
return new FileListStream(fileList, options);
this.files = [].slice.call(fileList).map(function (file) {
return new FileStream(file, options);
});
this.files.forEach(function (file, idx) {
this[idx] = file;
}, this);
};
function FileStream(file, options) {
if (!(this instanceof FileStream))
return new FileStream(file, options);
options = options || {};
options.output = options.output || 'binary';
this.options = options;
this._file = file;
this.readable = true;
['name',
'size',
'type',
'lastModifiedDate'].forEach(function (thing) {
this[thing] = file[thing];
}, this);
};
FileStream.prototype.pipe = function pipe(dest, options) {
const outputType = this.options.output;
const reader = new FileReader();
reader.onload = function loaded(event) {
dest.write(event.target.result);
if (dest !== console && (!options || options.end !== false)) {
if (dest.end)
dest.end();
if (dest.close)
dest.close();
}
};
if (outputType === 'binary')
reader.readAsBinaryString(this._file);
else if (outputType === 'dataurl')
reader.readAsDataURL(this._file);
else if (outputType === 'arraybuffer')
reader.readAsArrayBuffer(this._file);
else if (outputType === 'text')
reader.readAsText(this._file);
return dest;
};
module.exports = FileListStream;

View File

@@ -0,0 +1,35 @@
{
"name": "fileliststream",
"version": "0.0.2",
"description": "Convert a DOM FileList to a FileListStream",
"main": "index.js",
"dependencies": {
"browserify": "~1.17.2"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/brianloveswords/fileliststream.git"
},
"keywords": [
"filelist",
"fileliststream",
"dom",
"filereader"
],
"author": {
"name": "Brian J. Brennan"
},
"license": "MIT",
"readmeFilename": "README.md",
"gitHead": "b81694fd3cc54de6f5efd9a738977b99db431495",
"readme": "# fileliststream\n\nGiven a FileList, turn it into a FileListStream.\n\n# install\n\nUse it with npm & [browserify](/substack/node-browserify)\n\n```bash\n$ npm install fileliststream\n```\n\n# example\n```js\nconst FileListStream = require('fileliststream');\nconst body = document.body;\n\n// make it so console can be piped to.\nconsole.write = console.log;\n\nfunction noop(event) {\n event.preventDefault();\n event.stopPropagation();\n return false;\n};\n\n['dragenter',\n 'dragleave',\n 'dragexit',\n 'dragover'\n].forEach(function (eventType) {\n body.addEventListener(eventType, noop);\n});\n\nbody.addEventListener('drop', function (event) {\n event.stopPropagation();\n event.preventDefault();\n\n const fileList = FileListStream(event.dataTransfer.files);\n\n fileList.files.map(function(file) {\n file.pipe(console);\n });\n\n return false;\n});\n```\n\n# usage\n\n```js\nFileListStream(fileList, [options])\n```\n\n`options` currently has one possible parameter, `output`. Possible values are:\n\n* `binary` [default]\n* `dataurl`\n* `arraybuffer`\n* `text`\n",
"_id": "fileliststream@0.0.2",
"dist": {
"shasum": "3b12f9d8ad4df169fd40c6d674827d416a68aab1"
},
"_from": "fileliststream@~0.0.1"
}