-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathZDeflate_ZInflate_Test.jsx
More file actions
83 lines (67 loc) · 2.23 KB
/
ZDeflate_ZInflate_Test.jsx
File metadata and controls
83 lines (67 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*******************************************************************************
Name: ZDeflate/ZInflate Test
Desc: Test compression and decompression modules.
Path: /tests/ZDeflate_ZInflate_Test.jsx
Require: $$.ZDeflate ; $$.ZInflate
Encoding: ÛȚF8
Core: ---
Kind: Test script for InDesign.
API: ---
DOM-access: NO
Todo: ---
Created: 260106 (YYMMDD)
Modified: 260205 (YYMMDD)
*******************************************************************************/
#include '../$$.jsxinc'
#include '../etc/$$.ZDeflate.jsxlib'
#include '../etc/$$.ZInflate.jsxlib'
$$.load();
try
{
var fd = File($$.Env.runningScript).parent + '/ZDeflateInflate';
var HUGE = $$.File.readBinary(fd+'/huge.txt') || error( __("Huge File not found.") );
var SHORT = $$.File.readBinary(fd+'/short.txt') || error( __("Short File not found.") );
var INDD = new File(fd + '/test.indd');
INDD.exists || error( __("Test File (indd) not found.") );
const LOG = $$.Log.push;
var dt,src,data,cmp,ucp;
if( $$.dual("Select the zip/unzip Test:", "Huge String", "INDD File") )
{
src = HUGE;
$$.ZDeflate.ForceInternal = 1;
$$.ZInflate.ForceInternal = 1;
LOG("ZIP/UNZIP HUGE STRING (using slow internal methods)");
LOG("=====================");
}
else
{
src = INDD;
$$.ZDeflate.ForceInternal = 0;
$$.ZInflate.ForceInternal = 0;
LOG("ZIP/UNZIP INDD FILE (using fast external methods)");
LOG("===================");
}
data = 'string' == typeof src ? src : $$.File.readBinary(src);
LOG( __(" Original (%1 bytes):", data.length) );
LOG( data.trunc(120, ' (...) ').toSource() );
LOG();
dt = -new Date;
cmp = $$.ZDeflate.zip(src);
dt += +new Date;
LOG( __(" Compr (%2 ms): %1 bytes",cmp.length, dt) );
alert( "Compressed." );
dt = -new Date;
ucp = $$.ZInflate(cmp); // 'agnostic' decompressor
dt += +new Date;
LOG( __(" Uncomp (%2 ms): %1 bytes",ucp.length, dt) );
LOG();
'string' == typeof ucp || (ucp=$$.File.readBinary(ucp));
LOG( __(" Orig === uncomp: %1", data===ucp) );
LOG();
alert( "Done." );
}
catch(e)
{
$$.receiveError(e);
}
$$.unload();