Skip to content

Commit

Permalink
FileBufferReader.js updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Sep 15, 2014
1 parent db6e84c commit 991ba21
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 3 additions & 1 deletion FileBufferReader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated at Sep 07, 2014, 08:32:23
// Last time updated at Sep 14, 2014, 08:32:23

// Latest file can be found here: https://cdn.webrtc-experiment.com/FileBufferReader.js

Expand All @@ -15,6 +15,7 @@
// binarize.js is written by @agektmr: https://github.com/agektmr/binarize.js.

/* issues/features need to be fixed & implemented:
-. "onEnd" for sender now having "url" property as well; same as file receiver.
-. "extra" must not be an empty object i.e. {} -because "binarize" fails to parse empty objects.
-. "extra" must not have "date" types; -because "binarize" fails to parse date-types.
*/
Expand All @@ -30,6 +31,7 @@

File.Read(file, function(args) {
file.extra = extra || {};
file.url = URL.createObjectURL(file);
args.file = file; // passed over "onEnd"
fileBufferReader.chunks[args.uuid] = args;
callback(args.uuid);
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# [FileBufferReader.js](https://github.com/muaz-khan/FileBufferReader) [![npm](https://img.shields.io/npm/v/fbr.svg)](https://npmjs.org/package/fbr) [![downloads](https://img.shields.io/npm/dm/fbr.svg)](https://npmjs.org/package/fbr) / [Demo](https://www.WebRTC-Experiment.com/FileBufferReader/)
# [FileBufferReader.js](https://github.com/muaz-khan/FileBufferReader) [![npm](https://img.shields.io/npm/v/fbr.svg)](https://npmjs.org/package/fbr) [![downloads](https://img.shields.io/npm/dm/fbr.svg)](https://npmjs.org/package/fbr)

Demo: https://www.WebRTC-Experiment.com/FileBufferReader/

Using FileBufferReader.js, you can:

Expand Down Expand Up @@ -30,6 +32,15 @@ To use it:
<script src="./node_modules/fbr/FileBufferReader.js"></script>
```

## FileBufferReader API

1. `chunks` object. It contains multiple files' chunks. Even if you received chunks from remote peer, and invoked `addChunk` method; all chunks will be stored in same `chunks` object. `var fileChunks = fileBufferReader.chunks['file-uuid']`.
2. `readAsArrayBuffer` method. It reads entire file and stores chunkified buffers in `chunks` object.
3. `getNextChunk` method. It simply reads `last-position` and returns next available array-buffer chunk.
4. `onBegin`, `onEnd` and `onProgress` events. These are added only to support file progress bars.
5. `addChunk` method. It allows you store all received chunks in an array until entire file is received.
6. `convertToObject` method. FileBufferReader assumes that you're sending ArrayBuffer using WebRTC data channels. It means that you'll be getting ArrayBuffer type in the `onmessage` event. `convertToObject` method allows you convert ArrayBuffer into JavaScript object type, which is helpful to check type of message.

## 1. Link The Library

```
Expand Down Expand Up @@ -101,7 +112,7 @@ datachannel.onmessage = function(event) {
// array buffers are passed using WebRTC data channels
// need to convert data back into JavaScript objects

fileBufferReader.ConvertToObject(chunk, function(object) {
fileBufferReader.convertToObject(chunk, function(object) {
datachannel.onmessage({
data: object
});
Expand Down Expand Up @@ -175,6 +186,10 @@ fileBufferReader.onProgress = FileHelper.onProgress;
fileBufferReader.onEnd = FileHelper.onEnd;
```

## Applications using FileBufferReader

1. [RTCMultiConnection.js](http://www.RTCMultiConnection.org/)

## Credits

[Muaz Khan](https://github.com/muaz-khan):
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fbr",
"preferGlobal": true,
"version": "1.0.1",
"version": "1.0.2",
"author": {
"name": "Muaz Khan",
"email": "[email protected]",
Expand Down Expand Up @@ -44,6 +44,6 @@
"email": "[email protected]"
},
"homepage": "https://www.WebRTC-Experiment.com/FileBufferReader/",
"_id": "[email protected].1",
"_id": "[email protected].2",
"_from": "fbr@"
}

0 comments on commit 991ba21

Please sign in to comment.