forked from nlzv/isc_zip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_Library.zip.class.xml
827 lines (747 loc) · 22 KB
/
_Library.zip.class.xml
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Class name="%Library.zip">
<Description>
Class to create and extract zip
https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
https://www.zlib.net/manual.htm
win 32 bit date time format https://msdn.microsoft.com/en-us/library/9kkf9tah.aspx
Not yet working on big endian platform
Limitation 32 bit for zip size and files in zip.
</Description>
<Super>%RegisteredObject</Super>
<TimeCreated>64918,52465.852234</TimeCreated>
<Property name="files">
<Type>%String</Type>
<MultiDimensional>1</MultiDimensional>
</Property>
<Property name="idxlfhfiles">
<Type>%String</Type>
<MultiDimensional>1</MultiDimensional>
</Property>
<Property name="cdrfiles">
<Type>%String</Type>
<MultiDimensional>1</MultiDimensional>
</Property>
<Property name="idxcdrfiles">
<Type>%String</Type>
<MultiDimensional>1</MultiDimensional>
</Property>
<Property name="fcomments">
<Description>
file comment</Description>
<Type>%String</Type>
<MultiDimensional>1</MultiDimensional>
</Property>
<Property name="LFHo">
<Type>%String</Type>
<MultiDimensional>1</MultiDimensional>
</Property>
<Property name="LFHbin">
<Type>%String</Type>
<MultiDimensional>1</MultiDimensional>
</Property>
<Property name="CDRo">
<Type>%String</Type>
<MultiDimensional>1</MultiDimensional>
</Property>
<Property name="CDRbin">
<Type>%String</Type>
<MultiDimensional>1</MultiDimensional>
</Property>
<UDLText name="T">
<Content><![CDATA[
// the name of zip/pack file
]]></Content>
</UDLText>
<Property name="packfile">
<Type>%String</Type>
</Property>
<Property name="lfhlen">
<Description>
length static part of list file header</Description>
<Type>%Integer</Type>
</Property>
<Property name="gzipminhdrlen">
<Type>%Integer</Type>
</Property>
<Property name="lfhoffset">
<Description>
auxilary var to track location of LFH in packfile</Description>
<Type>%Integer</Type>
</Property>
<Property name="error">
<Type>%String</Type>
</Property>
<Property name="ZipComment">
<Description>
zip comment</Description>
<Type>%String</Type>
</Property>
<Property name="SourceDirectory">
<Description>
source directory
add file from this directory
it becomes current during pack()</Description>
<Type>%String</Type>
</Property>
<Property name="TargetDir">
<Type>%String</Type>
</Property>
<Property name="TargetSubDirs">
<Description>
check wether directory is created</Description>
<Type>%String</Type>
</Property>
<Property name="use">
<Description>
use = 0 existed archive extraxt
use = 1 create archive add</Description>
<Type>%Boolean</Type>
</Property>
<Property name="ZE">
<Description>
$ZERROR saved</Description>
<Type>%String</Type>
</Property>
<Property name="endian">
<Description>
0 little endian platform
1 big endian platform</Description>
<Type>%Boolean</Type>
</Property>
<Property name="time">
<Description>
time of the last pack/unpack function</Description>
<Type>%String</Type>
</Property>
<Property name="size">
<Description>
size during pack/unpack functions</Description>
<Type>%String</Type>
</Property>
<Property name="wsize">
<Description>
writing size during pack/unpack functions</Description>
<Type>%String</Type>
</Property>
<Method name="open">
<Description>
return %zip object open existed zip archive
files is populated</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>zipfile</FormalSpec>
<Implementation><![CDATA[
set eofold=$SYSTEM.Process.SetZEOF(1)
set zip=..%New()
try { close zipfile } catch {} open zipfile:("RUK\RAW\"):1
if $test='1 set zip.error="open file" quit zip
set lfhsig=..lfhsig()
set cdrsig=..cdrsig()
set eocdrsig=..eocdrsig()
set zip64eocdrsig=..zip64eocdrsig()
set zip64eocdlsig=..zip64eocdlsig()
set lfhlen=..structlen(..lfhmeta())
set cdrlen=..structlen(..cdrmeta())
set eocdrlen=..structlen(..eocdrmeta())
use zipfile
set foffset=0
set ilfh=0 set icdr=0
set fnlen=0,ziplen=0,extralen=0
set err=0
read bin#4 set foffset=foffset+4
if $E(bin,$L(bin)-3,$L(bin))'=lfhsig { for { read x#1 if $zeof=-1 { set err=1 quit } if foffset>512 { set err=2 quit } set bin=bin_x set foffset=foffset+1 if $E(bin,$L(bin)-3,$L(bin))=lfhsig || ($E(bin,$L(bin)-3,$L(bin))=cdrsig) { quit } }}
if err>0 set zip.error=err quit zip
#;B ; open start
for {
if bin=lfhsig {
#;B ;LFH start
set lfhbin=bin read bin#(lfhlen-4) set lfhbin=lfhbin_bin set ilfh=ilfh+1
set zip.LFHo(ilfh)=foffset-4
do ..getLFH(lfhbin,.sig,.version,.flag,.CompressionMethod,.time,.date,.crc,.zipsize,.size,.fnlen,.extralen)
if fnlen>0 { read fname#fnlen set zip.files(ilfh)=fname } else { set fname="" }
if extralen>0 { read extra#extralen } else { set extra="" }
#; data descriptor
if $zb(flag,8,1) {
B ;data descriptor not implemented
}
set zip.LFHbin(ilfh)=lfhbin_fname_extra
set foffset=foffset+lfhlen-4+fnlen+extralen+zipsize
use zipfile:foffset
#;B ;LFH end
}
#; file data 1
#; data descrriptor 1
#; common directory record
elseif bin=cdrsig {
#;B ; CDR start
set cdrbin=bin read bin#(cdrlen-4) set icdr=icdr+1 set cdrbin=cdrbin_bin
set zip.CDRo(icdr)=foffset-4
do ..getCDH(cdrbin, .sig, .madever, .extrver, .flag, .meth, .ftime, .fdate, .crc, .zipsize, .size, .fnlen, .extralen, .fclen, .dns, .ifa, .efa, .rolh)
set foffset=foffset+cdrlen-4
if fnlen>0 { read fname#fnlen set zip.cdrfiles(icdr)=fname } else { set fname="" }
if extralen>0 { read extra#extralen } else { set extra=""}
if fclen>0 { read fcomment#fclen set zip.fcomment(icdr)=fcomment } else { set fcomment="" }
set zip.CDRbin(icdr)=cdrbin_fname_extra_fcomment
set foffset=foffset+fnlen+extralen+fclen
use zipfile:foffset
#;B ; CDR end
}
#;
elseif bin=zip64eocdrsig {
B ;
}
elseif bin=zip64eocdlsig {
B ;
}
#; end of central directory record
elseif bin=eocdrsig {
#;B ; end of central directory start
set eocdrbin=bin read bin#eocdrlen-4 set eocdrbin=eocdrbin_bin
do ..getEOCDR(eocdrbin,.sig,.zipcommentlen)
if zipcommentlen>0 read v#zipcommentlen set zip.ZipComment=v
#;B ; end of central directory end
quit
}
read bin#4 set foffset=foffset+4
}
use 0 close zipfile
set zip.packfile=zipfile
do zip.BuildFileIndex()
if eofold=0 do $SYSTEM.Process.SetZEOF(0)
quit zip
]]></Implementation>
</Method>
<Method name="pack">
<Description>
create zip archive with list of files in files property
SourceDirectory relative
packfile argument override packfile property</Description>
<FormalSpec>packfile=""</FormalSpec>
<Implementation><![CDATA[
set ..time=$zh
set ..size=0
if packfile="" { set packfile=..packfile }
else { set ..packfile=packfile }
try { close packfile } catch {} open packfile:("NWUK\RAW\")
use packfile
set dir=$SYSTEM.Process.CurrentDirectory(..SourceDirectory)
set ..lfhoffset=0
set i="" for { set i=$order(..files(i),1,file) quit:i="" do ..packAddFileById(i) }
use packfile:..lfhoffset
set cdroffset=..lfhoffset
#; write CDRs
#;B ; start add CDRs
set len=""
set i="" for {
set i=$order(..LFHbin(i),1,binlfh) quit:i=""
do ..mkCDRfromLFH(.bincdr,binlfh,..LFHo(i))
set len=len+$L(bincdr)
W bincdr
}
#; write end of CDR
#;B ; write end of CDR
set n=$order(..files(""),-1)
do ..mkEOCDR(.bineocdr,cdroffset,len,n)
W bineocdr
close packfile
do $SYSTEM.Process.CurrentDirectory(dir)
set ..time=$zh-..time
]]></Implementation>
</Method>
<Method name="packAddFileById">
<Description>
add one file to packfile</Description>
<FormalSpec>id</FormalSpec>
<Implementation><![CDATA[
#;B ; start pack add file by id
set file=..files(id)
set packfile=..packfile
set gzipminhdrlen=..gzipminhdrlen
set lfhoffset=..lfhoffset
use packfile:lfhoffset
set size=##class(%File).GetFileSize(file)
set ..size=..size+size
set hlocalmoddattime=$zu(140,2,file,0)
set tsodbc=$zdt(hlocalmoddattime,3)
set date=..dosDateYMDtoBin($E(tsodbc,1,4),$E(tsodbc,6,7),$E(tsodbc,9,10))
set time=..dosTimeHMStoBin($E(tsodbc,12,13),$E(tsodbc,15,16),$E(tsodbc,18,19))
#;B ; before make lfh
do ..mkLFH(.binlfh,$C(20,0),$C(0,0),$C(8,0),time,date,/*crc*/,/*zipsize*/,size)
#;B ; after make lfh
do ..LFHsetFile(.binlfh,file)
set ..LFHbin(id)=binlfh
use packfile:..lfhoffset
W binlfh
set rawoffset=..lfhoffset+..lfhFullLen(binlfh)-gzipminhdrlen
use packfile:rawoffset
use packfile:(/GZIP=1)
try { close file } catch {} open file:("RUK\RAW\")
set len=0
#;B ; zip
for {
use file read bin
use packfile write bin
set len=len+$L(bin)
if len'<size quit
}
close file
close packfile
set offset=##class(%File).GetFileSize(packfile)-8
open packfile:("RWUK\RAW\")
use packfile:(/GZIP=0)
use packfile:offset
#;B ; read gzip tailor
read crc#4 read isize#4
set zipsize=offset-..lfhoffset-..lfhFullLen(binlfh)
#;B ;zipsize is calculated
do ..LFHsetCRC(.binlfh,crc)
do ..LFHsetZipSize(.binlfh,zipsize)
use packfile:..lfhoffset
W binlfh
set ..LFHbin(id)=binlfh
set ..LFHo(id)=..lfhoffset
set ..lfhoffset=offset
#;B ; pack add file by id end
]]></Implementation>
</Method>
<Method name="unpack">
<Description>
unzip archive</Description>
<FormalSpec>zipfile="",targdetdir=""</FormalSpec>
<Implementation><![CDATA[
set idlast=$order(..files(""),-1)
for id=1:1:idlast {
do zip.unpackbyid(id,targetdir)
}
]]></Implementation>
</Method>
<Method name="unpackSel">
<Description>
unpack only selected files</Description>
<FormalSpec>zipfile="",targetdir=""</FormalSpec>
</Method>
<Method name="unpackfile">
<Description>
unpack just one file</Description>
<FormalSpec>file</FormalSpec>
</Method>
<Method name="unpackbyid">
<FormalSpec>id,targetdir</FormalSpec>
<Implementation><![CDATA[
set $ztrap="exit"
set ..ZE=""
set restorepack=0
set packfile=..packfile
set lfhbin=..LFHbin(id)
set filename=..files(id)
#; check directory of file and create it
#;if '$data(..TargetDir) { }
set offset=..LFHo(id)
close packfile
open packfile:("RWUK\RAW\") use packfile
do ..getLFH(..LFHbin(id),,.ver,.flag,.meth,.time,.date,.crc,.zipsize,.size,.fnlen,.extralen)
set oraw=offset+$L(..LFHbin(id))
set gzipminhdr=..gzipminhdr()
set gziphdrlen=$L(gzipminhdr)
set ogziphdr=oraw-gziphdrlen
#;B ; gziphdr end
set ogziptlr=offset+..structlen(..lfhmeta())+fnlen+extralen+zipsize
set gziptlr=..gziptlr(crc,size)
set gziptlrlen=$L(gziptlr)
set restorepack=1
#; now put in file gziphdr
use packfile:ogziphdr
read savedgziphdr#gziphdrlen
use packfile:ogziphdr
write gzipminhdr
#; now put in file gziptlr
use packfile:ogziptlr
read savedgziptlr#gziptlrlen
use packfile:ogziptlr
write gziptlr
close packfile
set targetfile=targetdir_filename
#;B ;copy
open packfile:("RUK\RAW\")
use packfile:ogziphdr
use packfile:(/GZIP=1)
open targetfile:("NWUK\RAW\")
set len=0
set buflen=65536
B ;loop
for {
use packfile
if len+buflen<size { read bin#buflen }
else { read bin#(size-len)}
set len=len+$L(bin)
use targetfile write bin
if len'<size quit
}
close packfile
close targetfile
#; restore updates gzip header and tailer back
exit
if restorepack {
open packfile:("WUK\RAW\")
if $data(savedgziphdr) {
use packfile:ogziphdr
write savedgziphdr
}
if $data(savedgziptlr) {
use packfile:ogziptlr
write savedgziptlr
}
close packfile
}
quit
error
set $ztrap=""
set ..ZE=$ZE
goto exit
]]></Implementation>
</Method>
<Method name="getLFH">
<ClassMethod>1</ClassMethod>
<FormalSpec>bin,magic,version,flag,method,time,date,crc,zipsize,size,fnlen,extralen</FormalSpec>
<Implementation><![CDATA[
set magic=$E(bin,1,4)
set version=$E(bin,5,6)
set flag=$E(bin,7,8)
set method=$E(bin,9,10)
set time=$E(bin,11,12)
set date=$E(bin,13,14)
set crc=$E(bin,15,18)
set zipsize=$ZLA($E(bin,19,22))
set size=$ZLA($E(bin,23,26))
set fnlen=$ZWA($E(bin,27,28))
set extralen=$ZWA($E(bin,29,30))
quit
]]></Implementation>
</Method>
<Method name="LFHgetLengths">
<ClassMethod>1</ClassMethod>
<FormalSpec>bin,fnlen,extralen</FormalSpec>
<Implementation><![CDATA[
set fnlen=$ZWA($E(bin,27,28))
set extralen=$ZWA($E(bin,29,30))
]]></Implementation>
</Method>
<Method name="lfhFullLen">
<FormalSpec>bin</FormalSpec>
<Implementation><![CDATA[
do ..LFHgetLengths(.bin,.fnlen,.extralen)
quit ..lfhlen+fnlen+extralen
]]></Implementation>
</Method>
<Method name="mkLFH">
<ClassMethod>1</ClassMethod>
<FormalSpec>bin,version="",flag="",method="",time="",date="",crc="",packsize="",size="",fnlen="",extralen=""</FormalSpec>
<Implementation><![CDATA[
set lfhlen=..lfhlen()
if $L($G(bin))<lfhlen set bin=$TR($J("",lfhlen)," ",$C(0))
set $E(bin,1,4)=..lfhsig()
#; default 2.0
if version'="" set $E(bin,5,6)=version
if flag'="" set $E(bin,7,8)=flag
if method'="" set $E(bin,9,10)=method
if time'="" && ($L(time)=2) set $E(bin,11,12)=time
if date'="" && ($L(date)=2) set $E(bin,13,14)=date
if packsize'="" set $E(bin,19,22)=$ZLC(packsize)
if size'="" set $E(bin,23,26)=$ZLC(size)
if fnlen'="" set $E(bin,27,28)=$ZWC(fnlen)
if extralen'="" set $E(bin,29,30)=$ZWC(extralen)
]]></Implementation>
</Method>
<Method name="LFHsetFile">
<ClassMethod>1</ClassMethod>
<FormalSpec>bin,file</FormalSpec>
<Implementation><![CDATA[
do ..getLFH(.bin,.fnlenold,.extralen)
set lfhlen=..structlen(..lfhmeta())
set binhead=$E(bin,1,lfhlen)
set fnold=$E(bin,lfhlen+1,lfhlen+fnlenold)
set binextra=$E(bin,lfhlen+fnlenold+1,lfhlen+fnlenold+extralen)
set $E(binhead,27,28)=$ZWC($L(file))
set bin=binhead_file_binextra
]]></Implementation>
</Method>
<Method name="LFHsetCRC">
<ClassMethod>1</ClassMethod>
<FormalSpec>bin,crc</FormalSpec>
<Implementation><![CDATA[ set $E(bin,15,18)=crc
]]></Implementation>
</Method>
<Method name="LFHsetZipSize">
<ClassMethod>1</ClassMethod>
<FormalSpec>bin,zipsize</FormalSpec>
<Implementation><![CDATA[ set $E(bin,19,22)=$ZLC(zipsize)
]]></Implementation>
</Method>
<Method name="getLFSrawstream">
<FormalSpec>id</FormalSpec>
<Implementation><![CDATA[
set foffset=..LFHo(id)
do ..getLFH(..LFHbin(id),,.ver,.flag,.meth,.time,.date,.crc,.zipsize,.size,.fnlen,.extralen)
quit foffset+..structlen(..lfhmeta())+fnlen+extrlen
]]></Implementation>
</Method>
<Method name="getCDH">
<Description>
parse Central Directory Header</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>bin,sig,madever,extrver,flag,meth,ftime,fdate,crc,zipsize,size,fnlen,extralen,fclen,dns,ifa,efa,rolh</FormalSpec>
<Implementation><![CDATA[
set sig=$E(bin,1,4)
set madever=$ZWA(bin,5)
set extrver=$ZWA(bin,7)
set flag=$E(bin,9,10)
set meth=$E(bin,11,12)
set ftime=$E(bin,13,14)
set fdate=$E(bin,15,16)
set crc=$E(bin,17,20)
set zipsize=$ZLA($E(bin,21,24))
set size=$ZLA($E(bin,25,28))
set fnlen=$ZWA($E(bin,29,30))
set extralen=$ZWA($E(bin,31,32))
set fclen=$ZWA($E(bin,33,34))
set dns=$ZWA($E(bin,35,36))
set ifa=$E(bin,37,38)
set efa=$E(bin,39,42)
set rolh=$E(bin,43,46)
quit
]]></Implementation>
</Method>
<Method name="mkCDRfromLFH">
<ClassMethod>1</ClassMethod>
<FormalSpec>cdrbin,lfhbin,lfho="",ifa="",efa="",fcomment=""</FormalSpec>
<Implementation><![CDATA[
set lfhlen=..structlen(..lfhmeta())
set cdrlen=..structlen(..cdrmeta())
set cdrbin=$TR($J("",cdrlen)," ",$C(0))
set $E(cdrbin,1,4)=..cdrsig()
set $E(cdrbin,5,6)=$E(lfhbin,5,6)
set $E(cdrbin,7,8)=$E(lfhbin,5,6)
#; flag
set $E(cdrbin,9,10)=$E(lfhbin,7,8)
#; method
set $E(cdrbin,11,12)=$E(lfhbin,9,10)
#; time
set $E(cdrbin,13,14)=$E(lfhbin,11,12)
#; date
set $E(cdrbin,15,16)=$E(lfhbin,13,14)
#; crc
set $E(cdrbin,17,20)=$E(lfhbin,15,18)
#; compressed size
set $E(cdrbin,21,24)=$E(lfhbin,19,22)
#; uncompressed size
set $E(cdrbin,25,28)=$E(lfhbin,23,26)
#; filename len
set fnlen=$E(lfhbin,27,28)
set $E(cdrbin,29,30)=fnlen
set fnlen=$ZWA(fnlen)
#; extra len
set extralen=$E(lfhbin,29,30)
set $E(cdrbin,31,32)=extralen
set extralen=$ZWA(extralen)
if lfho'="" set $E(cdrbin,43,46)=$ZLC(lfho)
#; fcomment
if fcomment'="" { set $E(bin,33,34)=$ZWC($L(fcomment)) }
set cdrbin=cdrbin_$E(lfhbin,lfhlen+1,lfhlen+fnlen)_$E(lfhbin,lfhlen+fnlen+1,lfhlen+fnlen+extralen)_fcomment
]]></Implementation>
</Method>
<Method name="dumpCDR">
<ClassMethod>1</ClassMethod>
<FormalSpec>bin</FormalSpec>
<Implementation><![CDATA[
do ..getCDH(bin, .sig, .madever, .extrver, .flag, .meth, .ftime, .fdate, .crc, .zipsize, .size, .fnlen, .extralen, .fclen, .dns, .ifa, .efa, .rolh)
W "file comment length",fclen,!
quit
]]></Implementation>
</Method>
<Method name="lfhsig">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[ quit $zlc($zhex("04034b50"))
]]></Implementation>
</Method>
<Method name="cdrsig">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[ quit $zlc($zhex("02014b50"))
]]></Implementation>
</Method>
<Method name="zip64eocdrsig">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[ quit $zlc($zhex("06064b50"))
]]></Implementation>
</Method>
<Method name="zip64eocdlsig">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[ quit $zlc($zhex("07064b50"))
]]></Implementation>
</Method>
<Method name="eocdrsig">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[ quit $zlc($zhex("06054b50"))
]]></Implementation>
</Method>
<Method name="lfhlen">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
set LFHs=..lfhmeta()
set n=$LL(LFHs)
set len=0 for i=1:1:n set len=len+$LI($LI(LFHs,i),2)
quit len
]]></Implementation>
</Method>
<Method name="structlen">
<Description>
calculate length of struct basing on metainfo</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>meta</FormalSpec>
<Implementation><![CDATA[ set n=$LL(meta) set len=0 for i=1:1:n { set len=len+$LI($LI(meta,i),2) } quit len
]]></Implementation>
</Method>
<Method name="lfhmeta">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
quit $LB(
$LB("local file header signature",4),
$LB("version needed to extract",2),
$LB("general purpose bit flag",2),
$LB("compression method",2),
$LB("last mod file time",2),
$LB("last mod file date",2),
$LB("crc-32",4),
$LB("compressed size",4),
$LB("uncompressed size",4),
$LB("file name length",2),
$LB("extra field length",2)
)
]]></Implementation>
</Method>
<Method name="cdrmeta">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
quit $LB(
$LB("central file header signature",4),
$LB("version madeby",2),
$LB("version needed to extract",2),
$LB("general purpose bit flag",2),
$LB("compression method",2),
$LB("last mod file time",2),
$LB("last mod file date",2),
$LB("crc-32",4),
$LB("compressed size",4),
$LB("uncompressed size",4),
$LB("file name length",2),
$LB("extra field length",2),
$LB("file comment length",2),
$LB("disk number start",2),
$LB("internal file attributes",2),
$LB("external file attributes",4),
$LB("relative offset of local header",4)
)
]]></Implementation>
</Method>
<Method name="eocdrmeta">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
quit $LB(
$LB("end of central dir signature",4),
$LB("number of this disk",2),
$LB("number of the disk with the start of the central directory",2),
$LB("total number of entries in the central directory on this disk",2),
$LB("total number of entries in the central directory",2),
$LB("size of the central directory",4),
$LB("offset of start of central directory with respect to the starting disk number",4),
$LB("zip file comment length",2)
)
]]></Implementation>
</Method>
<Method name="getEOCDR">
<ClassMethod>1</ClassMethod>
<FormalSpec>bin,sig,zipcommentlen</FormalSpec>
<Implementation><![CDATA[
set sig=$E(bin,1,4)
set zipcommentlen=$zwa(bin,20)
]]></Implementation>
</Method>
<Method name="mkEOCDR">
<ClassMethod>1</ClassMethod>
<FormalSpec>bin,offset="",size="",n="",zipcomment=""</FormalSpec>
<Implementation><![CDATA[
set len=..structlen(..eocdrmeta())
set bin=$TR($J("",len)," ",$C(0))
set $E(bin,1,4)=..eocdrsig()
if n'="" {
#; total number of entries on this diks
set $E(bin,9,10)=$ZWC(n)
#; total number of entries
set $E(bin,11,12)=$ZWC(n)
}
if size'="" set $E(bin,13,16)=$ZLC(size)
if offset'="" { set $E(bin,17,20)=$ZLC(offset) }
if zipcomment'="" {
}
]]></Implementation>
</Method>
<Method name="BuildFileIndex">
<Implementation><![CDATA[
kill ..idxlfhfiles set i="" for { set i=$order(..files(i),1,file) quit:i="" set ..idxlfhfiles(file)=i }
kill ..idxcdrfiles set i="" for { set i=$order(..cdrfiles(i),1,file) quit:i="" set ..idxcdrfiles(file)=i }
]]></Implementation>
</Method>
<Method name="gzipminhdr">
<Description>
minimal gzip header</Description>
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[ quit $zlc($zh("088B1F"))_$C(0,0,0,0,0,3)
]]></Implementation>
</Method>
<Method name="gziptlr">
<Description>
crc is 4 binary bytes
size uncompressed length</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>crc,isize</FormalSpec>
<Implementation><![CDATA[ quit crc_$zlc(isize)
]]></Implementation>
</Method>
<Method name="dosDateTimeBinToString">
<ClassMethod>1</ClassMethod>
<FormalSpec>date,time</FormalSpec>
<Implementation><![CDATA[
set ndate=$zwa(date) set ntime=$zwa(time)
quit (1980+(ndate\512))_"-"_(ndate\32#16)_"-"_(ndate#32)_" "_ (ntime\2048)_":"_(ntime\32#32)_":"_((ntime#32)*2)
]]></Implementation>
</Method>
<Method name="dosTSYMDHMStoBin">
<Description>
YYYYMMDDHHMMSS</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>year,month,day,hour,minute,second</FormalSpec>
<Implementation><![CDATA[ quit $ZWC(year-1980*512+(month*32)+day)_$ZWC(hour*2048+(minute*32)+(second/2))
]]></Implementation>
</Method>
<Method name="dosDateYMDtoBin">
<ClassMethod>1</ClassMethod>
<FormalSpec>year,month,day</FormalSpec>
<Implementation><![CDATA[ quit $ZWC(year-1980*512+(month*32)+day)
]]></Implementation>
</Method>
<Method name="dosTimeHMStoBin">
<ClassMethod>1</ClassMethod>
<FormalSpec>hour,minute,second</FormalSpec>
<Implementation><![CDATA[ quit $ZWC(hour*2048+(minute*32)+(second/2))
]]></Implementation>
</Method>
<Method name="%OnNew">
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
set ..lfhlen=..lfhlen()
set ..gzipminhdrlen=$L(..gzipminhdr())
quit $$$OK
]]></Implementation>
</Method>
</Class>
</Export>