But there are so many API’s
• require, require.resolve
• fs.readFile, fs.readFileSync, fs.ReadStream
• fs.readlink, fs.stat, fs.statSync, fs.readlinkSync
• …
SquashFS
• a compressed read-only file system
• used by the Live CD versions of Arch
Linux, Debian, Fedora, Gentoo, Mint,
Salix, Ubuntu
• used on OpenWrt and DD-WRT router
firmware
Slide 41
Slide 41 text
fengdie’s
node_modules/
148M
fengdie.squashfs
16M
Slide 42
Slide 42 text
SquashFS
• Introduced in 2009 with Linux 2.6.29
• File format very stabilized
• Unsquashfs and mksquashfs have win32 ports;
7-Zip on win32 also supports SquashFS
• Part of kernel; GPL Licensed
Slide 43
Slide 43 text
Introducing libsquash
Slide 44
Slide 44 text
https://github.com/pmq20/libsquash
libsquash
• MIT licensed
• Super embeddable
• 1 dependency only, which
could be statically linked
• Compiles on 3 platforms, even
Windows XP with VC++ 2010
• Introduces VFD - virtual file
descriptor, intercepting
system calls unobtrusively
libsquash
Slide 45
Slide 45 text
API of libsuqash
mirroring system calls
Slide 46
Slide 46 text
Virtual File Descriptor
generated by a duplicating file descriptor 0
Slide 47
Slide 47 text
Use libsquash unobtrusively
Just include a header and it’s done!
Slide 48
Slide 48 text
Use libsquash unobtrusively
Win32 API works as well
Slide 49
Slide 49 text
Hard-code an Entrance
Slide 50
Slide 50 text
node ~/fengdie/bin/cli.js
(argv[1] preset to /__enclose_io_memfs__/bin/cli.js)
./fengdie
fengdie/*
fengdie.squashfs
libsquash
Node.js Runtime
fengdie.exe
Statically Link
Statically Link
Slide 58
Slide 58 text
fengdie/*
fengdie.squashfs
libsquash
Node.js Runtime
fengdie.exe
Statically Link
Statically Link
Slide 59
Slide 59 text
fengdie.exe
Distribute and Enjoy
Slide 60
Slide 60 text
Download & Install
Slide 61
Slide 61 text
nodec is also enclosed
Operating
System
Architecture
Download Link
Windows x86
https://sourceforge.net/projects/
node-compiler/files/v0.9.4/
nodec.exe/download
macOS x86-64
https://sourceforge.net/projects/
node-compiler/files/v0.9.4/nodec-
darwin-x64/download
Linux x86-64
https://sourceforge.net/projects/
node-compiler/files/v0.9.4/nodec-
linux-x64/download
Slide 62
Slide 62 text
Install on Windows
• SquashFS Tools 4.3
• Python 2.6 or 2.7
• Visual Studio 2015 Update 3, all editions including
the Community edition (remember to select
"Common Tools for Visual C++ 2015" feature
during installation).
• Then download the executable nodec.exe and run
it from the VC++ or VS Command Prompt.
Slide 63
Slide 63 text
Install on macOS
• SquashFS Tools 4.3: brew install squashfs
• Xcode + Command Line Tools
• Python 2.6 or 2.7
• GNU Make 3.81 or newer
Install on Linux
• SquashFS Tools 4.3
• gcc and g++ 4.8 or newer, or
• clang and clang++ 3.4 or newer
• Python 2.6 or 2.7
• GNU Make 3.81 or newer
Slide 66
Slide 66 text
Install on Linux
• curl -L https://sourceforge.net/projects/node-
compiler/files/v0.9.4/nodec-linux-x64/download
> nodec
• chmod +x nodec
• ./nodec
Slide 67
Slide 67 text
Licensing
Slide 68
Slide 68 text
Commercial-license-free
Slide 69
Slide 69 text
Proprietary-license-free
Slide 70
Slide 70 text
GPL-free
Slide 71
Slide 71 text
Super Redistributable
libsquash MIT
Node.js MIT
libuv MIT
v8 BSD
Slide 72
Slide 72 text
Super Redistributable
zlib zlib License
openssl
Apache
4-clause BSD
HTTP Parser MIT
c-ares MIT
Slide 73
Slide 73 text
Applications
Slide 74
Slide 74 text
Quicker Install / Upgrade
• Quicker upgrading embedded node.js
applications / plugins
• Quicker upgrading embedded node.js
applications / plugins
• E.g. fengdie inside the Tea IDE
Slide 75
Slide 75 text
Enabling Node.js Developers
• Build softwares instead of modules
• Distribute to non-technical users
• Merchandise by building personal / enterprise
softwares
Slide 76
Slide 76 text
Code Protection
• Enable code signing for the entire application;
guarantee not being altered or corrupted
• Prevent hacking by users modifying exposed
Javascript source code
• Applicable to NW.js applications (DingTalk) and
Electron applications (Tea)
Slide 77
Slide 77 text
Tips
Slide 78
Slide 78 text
Use --tmpdir=/a/fixed/location
Slide 79
Slide 79 text
Use CentOS release 5.8
with gcc and g++ 4.8
(possibly from devtoolset-2 of slc5-devtoolset)
Slide 80
Slide 80 text
Use Windows
with a big Virtual Memory
Slide 81
Slide 81 text
Check dependencies using
Dependency Walker, otool, ldd
before releasing