Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
janjongboom committed Apr 2, 2012
1 parent 48682ab commit d36f794
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
26 changes: 14 additions & 12 deletions demo.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
var fs = require("fs");
var zip = require("./index");

(function () {
var archive = new zip();

archive.add("hello.txt", new Buffer("Hello world", "utf8"));

var buffer = archive.toBuffer();
fs.writeFile("./test1.zip", buffer, function () {
console.log("Finished");
});
})
//(function () {
// var archive = new zip();
//
// archive.add("hello.txt", new Buffer("Hello world", "utf8"));
//
// var buffer = archive.toBuffer();
// fs.writeFile("./test1.zip", buffer, function () {
// console.log("Finished");
// });
//})



(function () {
var zip = require("./index");

var archive = new zip();
archive.addFiles([
{ name: "moehah.txt", path: "./test/moehah.txt" },
{ name: "images/sam.jpg", path: "./test/images.jpg" }
{ name: "test.txt", path: "./test/test.txt" }//,
//{ name: "images/sam.jpg", path: "./test/images.jpg" }
], function () {
var buff = archive.toBuffer();

Expand Down
17 changes: 15 additions & 2 deletions janzip/janzip.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ var Zip = function () {
var header = new RollingBuffer(26);

// version + bit flag
writeBytes(header, [ 0x0A, 0x00, 0x00, 0x00 ]);
writeBytes(header, [ 0x0A, 0x00, parseInt("0010", 2), parseInt("0000", 2) ]);
// compression method @todo multiple methods, this is STORE
writeBytes(header, compressIndicator);
// file time & date
header.writeInt16(dt.time);
header.writeInt16(dt.date);

// crc, and sizes are set afterwards

// crc32
header.writeInt32(crc32(compressedData));
// compressed size
Expand Down Expand Up @@ -141,11 +144,21 @@ var Zip = function () {
var fileHeader = getFileHeader(file, zipMethod.indicator, data);

// write files
var fileBuffer = new RollingBuffer(4 + fileHeader.length + file.name.length + data.length);
var fileBuffer = new RollingBuffer(4 + fileHeader.length + file.name.length + data.length + (4*4));
writeBytes(fileBuffer, [0x50, 0x4b, 0x03, 0x04]); // 4
fileBuffer.appendBuffer(fileHeader); // hmm...
fileBuffer.write(file.name, "ascii");
fileBuffer.appendBuffer(data);

// 0x08074b50
writeBytes(fileBuffer, [ 0x08, 0x07, 0x4b, 0x50 ]);

// crc32
fileBuffer.writeInt32(crc32(data));
// compressed size
fileBuffer.writeInt32(data.length);
// uncompressed size
fileBuffer.writeInt32(file.data.length);

// now create dir
var dirBuffer = new RollingBuffer(4 + 2 + fileHeader.length + 6 + 4 + 4 + file.name.length);
Expand Down

0 comments on commit d36f794

Please sign in to comment.