Compare commits

...

5 Commits

Author SHA1 Message Date
Jameson Little 5bdc55ed37 Removed require-kiss dependency in favor of pakmanager 2011-10-28 18:04:25 -06:00
Jameson Little f28fe10f6b Merge pull request #8 from jergason/patch-2
Fix bugs with this identifier and out array expansion
2011-10-28 13:48:29 -07:00
Jamison Dance c1a69341d3 Missing another `this` on `out`, and the bounds checking was totally borked.
Bounds checking bug was preventing the size of the out array from being expanded more than once.
2011-10-28 12:54:18 -06:00
Jameson Little fb15e86c44 Merge pull request #7 from jergason/patch-1
Fix bug in tar.js caused by missing `this` on a variable.
2011-10-24 10:06:52 -07:00
Jamison Dance 7f450b58e1 Fix bug in tar.js caused by missing `this` on a variable. 2011-10-22 01:12:59 -06:00
8 changed files with 58 additions and 56 deletions

View File

@ -17,14 +17,14 @@ Dependencies
Tar needs an HTML5 compliant browser. More specifically it needs `Uint8Array` to work.
The only external module is require-kiss, which makes browser JS much more Node-like.
The examples depend on pakmanager, a package manager for the browser to make code written for node run in the browser. Install it as such:
This module can be installed from npm (`npm install require-kiss`) or directly downloaded from github (https://github.com/coolaj86/require-kiss-js).
`pakmanager build`
Usage Guide
===========
In your HTML file, make sure that require-kiss is included first. Then, to use it, do something like this:
The easiest way to interface with it is by using pakmanager. Include the package from pakmanager in your html, and then in you javascript:
var Tar = require('tar'),
tape = new Tar();

View File

@ -3,41 +3,7 @@
<head>
<title>Browser Tar</title>
<script src='../node_modules/require-kiss/require-kiss.js'></script>
<script src='../lib/utils.js'></script>
<script src='../lib/header.js'></script>
<script src='../lib/tar.js'></script>
<script>
(function () {
"use strict";
var Tar = require('tar'),
utils = require('utils'),
tape = new Tar(),
out,
url,
base64;
function uint8ToString(buf) {
var i, length, out = '';
for (i = 0, length = buf.length; i < length; i += 1) {
out += String.fromCharCode(buf[i]);
}
return out;
}
out = tape.append('output.txt', 'This is test1!');
out = tape.append('dir/out.txt', 'This is test2! I changed up the directory');
out = tape.append('arr.txt', utils.stringToUint8('This is a Uint8Array!'));
base64 = btoa(uint8ToString(out));
url = "data:application/tar;base64," + base64;
window.open(url);
}());
</script>
<script src='./pakmanaged.js'></script>
</head>
<body>

38
examples/main.js Normal file
View File

@ -0,0 +1,38 @@
(function () {
"use strict";
var Tar = require('tar-js'),
tape = new Tar(),
out,
url,
base64;
function uint8ToString(buf) {
var i, length, out = '';
for (i = 0, length = buf.length; i < length; i += 1) {
out += String.fromCharCode(buf[i]);
}
return out;
}
function stringToUint8 (input) {
var out = new Uint8Array(input.length), i;
for (i = 0; i < input.length; i += 1) {
out[i] = input.charCodeAt(i);
}
return out;
}
out = tape.append('output.txt', 'This is test1!');
out = tape.append('dir/out.txt', 'This is test2! I changed up the directory');
out = tape.append('arr.txt', stringToUint8('This is a Uint8Array!'));
base64 = btoa(uint8ToString(out));
url = "data:application/tar;base64," + base64;
window.open(url);
}());

10
examples/package.json Normal file
View File

@ -0,0 +1,10 @@
{
"author": "",
"name": "tar-example",
"engines": {
"node": "~0.4.7"
},
"main": "./main.js",
"dependencies": {
}
}

View File

@ -6,8 +6,6 @@
(function () {
"use strict";
require('require-kiss');
/*
struct posix_header { // byte offset
char name[100]; // 0
@ -124,6 +122,4 @@ struct posix_header { // byte offset
module.exports.structure = headerFormat;
module.exports.format = formatHeader;
provide('header', module.exports);
}());

View File

@ -6,8 +6,6 @@
(function () {
"use strict";
require('require-kiss');
var header = require("./header"),
utils = require("./utils"),
recordSize = 512,
@ -80,9 +78,10 @@
this.written += headerArr.length;
// this makes sense if the input is greater than 512 bytes
if (headerArr.length + input.length > this.out.length) {
this.out = utils.extend(out, headerArr.length, input.length, blockSize);
// If there is not enough space in this.out, we need to expand it to
// fit the new input.
if (this.written + input.length > this.out.length) {
this.out = utils.extend(this.out, this.written, input.length, blockSize);
}
this.out.set(input, this.written);
@ -92,7 +91,7 @@
// make sure there's at least 2 empty records worth of extra space
if (this.out.length - this.written < recordSize * 2) {
this.out = utils.extend(out, this.written, recordSize * 2, blockSize);
this.out = utils.extend(this.out, this.written, recordSize * 2, blockSize);
}
if (typeof callback === 'function') {
@ -108,6 +107,4 @@
};
module.exports = Tar;
provide('tar', module.exports);
}());

View File

@ -6,8 +6,6 @@
(function () {
"use strict";
require('require-kiss');
var lookup = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
@ -90,6 +88,4 @@
module.exports.extend = extend;
module.exports.stringToUint8 = stringToUint8;
module.exports.uint8ToBase64 = uint8ToBase64;
provide('utils');
}());

View File

@ -1,7 +1,7 @@
{
"name": "tar-js",
"description": "Tar implemented in the browser",
"version": "0.1.1",
"version": "0.2.0",
"homepage": "http://github.com/beatgammit/tar-js",
"repository": {
"type": "git",
@ -14,6 +14,5 @@
"lib": "lib"
},
"dependencies": {
"require-kiss": "*"
}
}