• Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    JavaScript
  • Created almost 13 years ago
  • Updated almost 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Zipping in node.js with no external dependencies

This project has been abandoned in favor of node-archiver

If you're in need of a non-binary ZIP library for node.js, I'd like to redirect you to node-archiver.

node-native-zip

All the current ZIP solutions for node.js are wrappers around existing zip executables, spawning on demand. To all of you who rather have a native implementation of zip'ing in javascript there is node-native-zip. This package works with Buffer objects, which allows you to do complex in-memory stuff with the least amount of overhead.

It has been inspired by JSZip.

How to install

Via NPM:

npm install node-native-zip

Via GIT:

git clone git://github.com/janjongboom/node-native-zip.git

How to use

There are two ways to feed files into a new .zip file. Either by adding Buffer objects, or by adding an array of files.

Adding Buffer objects

    var fs = require("fs");
    var zip = require("node-native-zip");
    
    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");
    });

Adding files from the file system

    var fs = require("fs");
    var zip = require("node-native-zip");
    
    var archive = new zip();
    
    archive.addFiles([ 
        { name: "moehah.txt", path: "./test/moehah.txt" },
        { name: "images/suz.jpg", path: "./test/images.jpg" }
    ], function (err) {
        if (err) return console.log("err while adding files", err);
        
        var buff = archive.toBuffer();
        
        fs.writeFile("./test2.zip", buff, function () {
            console.log("Finished");
        });
    });

API Reference

There are three API methods:

  • add(name, data), the 'name' is the name within the .zip file. To create a folder structure, add '/'
  • addFiles(files, callback), where files is an array containing objects in the form { name: "name/in/zip.file", path: "file-system.path" }. Callback is a function that takes 1 parameter 'err' which indicates whether an error occured.
  • toBuffer(), creates a new buffer and writes the zip file to it

Compression?

The library currently doesn't do any compression. It stores the files via STORE. Main reason is that the compression call is synchronous at the moment, so the thread will block during compression, something to avoid. However, it is possible to add compression methods by implementing the following interface.

    module.exports = (function () {
        return {
            indicator : [ 0x00, 0x00 ],
            compress : function (content) {
                // content is a Buffer object.
                // you have to return a new Buffer too.
            }
        };
    }());

The indicator is an array consisting of two bytes indicating the compression technology. For example: [ 0x00, 0x00] is STORE, [ 0x08, 0x00] is DEFLATE.

The compress function is a method that transforms an incoming Buffer into a new one.

The easiest to implement is probably deflate, because there is a sample in JSZip. You will only need to change the inner workings from string-based to Buffer-based.

Unzipping

Unzipping is more complex because of all the different compression algorithms that you may encounter in the wild. So it's not covered. Use existing libraries for that.

More Repositories

1

mbed-simulator

Experimental simulator for Mbed OS 5 applications
C
174
star
2

janpatch

JojoDiff Alternative Patch library - portable C library for memory-efficient binary patching
C
133
star
3

Moth

Moth has all the awesomness Steve Souders thaught you about fast websites, but fully integrated in your ASP.NET MVC project!
JavaScript
27
star
4

ttn-sensor-maps

Create pretty looking maps of TTN sensor nodes
JavaScript
18
star
5

mbed-vscode-generator

Generate VSCode intellisense and build configuration for Mbed OS
JavaScript
17
star
6

alpine-opencv-docker

Pre-built OpenCV for armhf Alpine Linux 3.6
C++
15
star
7

arduino-mbed-mashup

Running Arduino sketches on Mbed OS
C
14
star
8

css-reflow-tracer

Helps track down CSS reflows
JavaScript
14
star
9

binary-diff-mbedos5

Using JANPatch to apply a binary diff in Mbed OS 5
C++
12
star
10

rollingspider.xyz

Fly a drone in your browser
JavaScript
10
star
11

mbed-os-example-fota-http

Firmware update over HTTP example for mbed OS 5
C++
7
star
12

neosensory-arduinoble

Talk to NeoSensory from ArduinoBLE
C++
7
star
13

fxos-physical-web

Physical Web app for Firefox OS
JavaScript
7
star
14

b-l475e-iot01a-audio-mbed

Mbed OS example on driving the MEMS microphones on ST IoT Discovery Board
C
6
star
15

sam-lorawan-mbedos5

Mbed OS 5 LoRaWAN stack running on SAML21 and SAMR34 Xplained Pro
C++
6
star
16

jdiff-js

JojoDiff in JavaScript
JavaScript
6
star
17

meetingroom-web

Meetingroom management with Physical Web, web part
JavaScript
5
star
18

stm32-standby-rtc-wakeup

Bring STM32 device into Standby mode and wake it from RTC (Mbed OS 5 library)
C
5
star
19

mbed-delta-update

Delta update library for Mbed OS 5
C
4
star
20

mbed-os-example-cryptoauthlib

Mbed OS 5 example program for interacting with Crypto Authentication secure elements
C
4
star
21

lorawan-fota-signing-tool

LoRaWAN Firmware Update signing tools for Mbed OS 5
JavaScript
4
star
22

mbed-coremark-lm32-printf

Small printf library for Mbed OS 5 - based on https://github.com/jpbonn/coremark_lm32
C
4
star
23

mbed-ws

WIP! Websocket client for Mbed OS
C++
4
star
24

dsa2018-greenhouse-monitor

Greenhouse monitoring system for DSA 2018
C++
4
star
25

mbed-cryptoauthlib

Mbed OS library for interacting with the Crypto Authentication secure elements
C++
4
star
26

janos-tracker-server

Simple server for the tracker
JavaScript
3
star
27

iot-devfest

IoT DevFest workshop 2019
C++
3
star
28

mbed-websocket

WIP!!! Sane, non-blocking websocket client for Mbed OS
C++
3
star
29

apializer

Api'alizer turns a website into an API
JavaScript
3
star
30

sxsw

Demo's for SXSW
C++
3
star
31

jsconf-us

JavaScript
3
star
32

jsconf-asia

Experiments for JSConf.asia
JavaScript
3
star
33

mbed-js-wrapper-generator

WIP C++ <> JerryScript wrapper generator
JavaScript
3
star
34

app-training-dhaka

Some small projects
JavaScript
3
star
35

mbed-lorawan-frag-lib

LoRaWAN fragmentation library
C++
2
star
36

hexiwear-cloud

Hexiwear to mbed Device Connector
C++
2
star
37

push-server

Simple push server and client for FFOS
JavaScript
2
star
38

koehandel

Just a game
JavaScript
2
star
39

mbed-os-example-http-server

HTTP Server for mbed OS 5 - work in progress
C++
2
star
40

c9integration

JavaScript
2
star
41

omg-awesome-homescreen

Simple third-party homescreen template for Firefox OS
JavaScript
2
star
42

apf-demo

JavaScript
2
star
43

mbed-js-simulator

Run mbed.js programs in your browser
JavaScript
2
star
44

mbed-find-dangling-pointers

Find dangling pointers in Mbed OS projects
JavaScript
2
star
45

threejs-dice-physics

A bunch of falling dice
JavaScript
2
star
46

socketioupload

Demonstration on how to use socket.io and nodejs to create a file sharing application
JavaScript
2
star
47

electricity-bus-tracker

Track buses in Gothenburg
JavaScript
1
star
48

mobileeast

Mobile East 2012 demo repository
JavaScript
1
star
49

internal-training-lora-2019

Internal training for LoRaWAN
C++
1
star
50

azure-private-key-extractor

C#
1
star
51

at45-blockdevice

mbed OS 5 block device driver for AT45 flash
C++
1
star
52

mak-maze

Maze game for FFOS
CSS
1
star
53

jsdom-demo

JavaScript
1
star
54

test123

1
star
55

dsa-firmware-2019

Firmware for DSA 2019
C++
1
star
56

lorawan-fragmentation-in-flash

Memory efficient implementation of LoRaWAN Datablock Fragmentation for mbed OS 5
C
1
star
57

arm-objdump-parser

Generate trees of C++ code by parsing objdump files
JavaScript
1
star
58

mbed-js-repl

JS REPL for mbed
C++
1
star
59

doodle-jump-fxos

JavaScript
1
star
60

tech-live-analytics

Tracking physical product engagement with Google Analytics
C++
1
star
61

mbed-os-example-lorawan-skt

SK Telecom LoRaWAN example for Mbed OS 5
C++
1
star
62

ttn-conf-workshop

The Things Network Conference - FOTA workshop material
JavaScript
1
star
63

connector-mqtt

mbed Device Connector over MQTT
JavaScript
1
star
64

md2mbed

Convert Markdown into formatted text for os.mbed.com
JavaScript
1
star
65

emscripten-node-mmap

mmap for emscripten's NODEFS lib
C++
1
star
66

mbed-os-example-lorawan-minimal

Minimal version of mbed-os-example-lorawan for Murata module
C++
1
star
67

mbed-os-example-blinky-no-rtos

Blinky for mbed OS 5 without using mbed RTOS
C++
1
star
68

6lowpan-notes

Notes for 6LoWPAN article
1
star
69

schizophrenia

JavaScript
1
star
70

mbed-tsl2572

Mbed OS driver for the TSL2572 ambient light sensor
C++
1
star
71

pelion-ready-plus-azure

Run Pelion Device Management and Azure IoT Hub Client on the same device
C++
1
star
72

mbed-os-dev-lorawan

SXSW 2018 Temp LoRaWAN fork of Mbed OS
C
1
star
73

mbed-config

Visual configuration system for Mbed OS
HTML
1
star
74

mbed-davis-anemometer

Mbed driver for Davis Anemometer
C++
1
star
75

google-maps-socketio-demo

Google Maps demo that let's you put pins on a map, by clicking or via geocode. Plus it distributes them to all others with the window open as well. Collaboration ftw!
JavaScript
1
star
76

dsa2017-fieldwork-fw

Firmware for fieldwork during DSA2017
C++
1
star