Skip to content

Commit 31f85b9

Browse files
author
Brent Cook
committed
add comments
1 parent cdcf4cc commit 31f85b9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

data/post/zip/zip.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
/*
2+
* Original technique from http://naterice.com/zip-and-unzip-files-using-the-windows-shell-and-vbscript/
3+
*/
4+
15
function create_zip(dst)
26
{
37
var header = "\x50\x4b\x05\x06" +
48
"\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
59
"\x00\x00\x00\x00\x00\x00\x00\x00\x00";
610

11+
/*
12+
* Trick to write a binary file regardless of the system locale
13+
*/
714
var outw = new ActiveXObject("ADODB.Stream");
815
outw.Type = 2;
916
outw.Open();
@@ -38,13 +45,23 @@ function zip(src, dst)
3845
{
3946
var shell = new ActiveXObject('Shell.Application');
4047
var fso = new ActiveXObject('Scripting.FileSystemObject');
48+
49+
/*
50+
* Normalize paths, required by the shell commands
51+
*/
4152
src = fso.GetAbsolutePathName(src);
4253
dst = fso.GetAbsolutePathName(dst);
4354

55+
/*
56+
* Create an empty zip file if necessary
57+
*/
4458
if (!fso.FileExists(dst)) {
4559
create_zip(dst);
4660
}
4761

62+
/*
63+
* Check for duplicates
64+
*/
4865
var zipfile = shell.Namespace(dst);
4966
var files = zipfile.items();
5067
var count = files.Count;
@@ -55,6 +72,11 @@ function zip(src, dst)
5572
}
5673

5774
zipfile.CopyHere(src);
75+
76+
/*
77+
* Wait for completion, but data can be stale on network shares, so we
78+
* abort after 5 seconds.
79+
*/
5880
var max_tries = 50;
5981
while (count == zipfile.items().Count) {
6082
WScript.Sleep(100);

0 commit comments

Comments
 (0)