Skip to content

Commit 77426bf

Browse files
committed
FEAT: Munge code updated using the new built-in ZIP encoder
1 parent 99a5c28 commit 77426bf

File tree

1 file changed

+3
-87
lines changed

1 file changed

+3
-87
lines changed

src/modules/munge3.reb

+3-87
Original file line numberDiff line numberDiff line change
@@ -176,92 +176,8 @@ ctx-munge: context [
176176
archive: function [ ; https://en.wikipedia.org/wiki/Zip_(file_format) & http://www.rebol.org/view-script.r?script=rebzip.r
177177
"Compress block of file and data pairs"
178178
source [series!]
179-
] compose/deep [
180-
to-short: function [i] [copy/part reverse to binary! i 2]
181-
to-long: function [i] [copy/part reverse to binary! i 4]
182-
183-
case [
184-
empty? source [none]
185-
not block? source [
186-
compress/gzip source
187-
]
188-
true [
189-
bin: copy #{}
190-
dir: copy #{}
191-
192-
foreach [file series] source [
193-
all [none? series series: make string! 0]
194-
195-
any [file? file cause-error 'user 'message reduce [reform ["found" type? file "where file! expected"]]]
196-
any [series? series cause-error 'user 'message reduce [reform ["found" type? series "where series! expected"]]]
197-
198-
method: either greater? length? series length? compressed-data: compress data: to binary! series [
199-
compressed-data: copy/part skip compressed-data 2 skip tail compressed-data -8
200-
#{0800} ; deflate
201-
] [
202-
compressed-data: data
203-
#{0000} ; store
204-
]
205-
206-
offset: length? bin
207-
208-
append bin rejoin [
209-
#{504B0304} ; Local file header signature
210-
#{1400} ; Version needed to extract (minimum)
211-
#{0000} ; General purpose bit flag
212-
method ; Compression method
213-
#{0000} ; File last modification time
214-
#{0000} ; File last modification date
215-
crc: to-long crc32 data
216-
compressed-size: to-long length? compressed-data
217-
uncompressed-size: to-long length? data
218-
filename-length: to-short length? file
219-
#{0000} ; Extra field length
220-
filename: to binary! file
221-
#{} ; Extra field
222-
compressed-data ; Data
223-
]
224-
225-
append dir rejoin [
226-
#{504B0102} ; Central directory file header signature
227-
#{1400} ; Version made by
228-
#{1400} ; Version needed to extract (minimum)
229-
#{0000} ; General purpose bit flag
230-
method ; Compression method
231-
#{0000} ; File last modification time
232-
#{0000} ; File last modification date
233-
crc ; CRC-32
234-
compressed-size ; Compressed size
235-
uncompressed-size ; Uncompressed size
236-
filename-length ; File name length
237-
#{0000} ; Extra field length
238-
#{0000} ; File comment length
239-
#{0000} ; Disk number where file starts
240-
#{0000} ; Internal file attributes
241-
#{00000000} ; External file attributes
242-
to-long offset ; Relative offset of local file header
243-
filename ; File name
244-
#{} ; Extra field
245-
#{} ; File comment
246-
]
247-
]
248-
249-
append bin rejoin [
250-
dir
251-
#{504B0506} ; End of central directory signature
252-
#{0000} ; Number of this disk
253-
#{0000} ; Disk where central directory starts
254-
entries: to-short divide length? source 2 ; Number of central directory records on this disk
255-
entries ; Total number of central directory records
256-
to-long length? dir ; Size of central directory
257-
to-long length? bin ; Offset of start of central directory
258-
#{0000} ; Comment length
259-
#{} ; Comment
260-
]
261-
262-
bin
263-
]
264-
]
179+
] [
180+
encode 'ZIP source
265181
]
266182

267183
call-out: function [
@@ -1392,7 +1308,7 @@ ctx-munge: context [
13921308
true [
13931309
either only [
13941310
tmp: codecs/zip/decode/only source to block! file
1395-
tmp/2/3 ; retuns only decompressed data
1311+
tmp/2/2 ; retuns only decompressed data
13961312
][ codecs/zip/decode source ]
13971313
]
13981314
]

0 commit comments

Comments
 (0)