@@ -179,7 +179,7 @@ def is_appledouble(file_byte_stream):
179
179
return True
180
180
181
181
def macbin_get_resfork_data (file_byte_stream ):
182
- """ Returns the resource fork's data section as bytes of a macbinary file as well as its size """
182
+ """ Returns the resource fork's data section as bytes, data fork size (size), resource fork size (size-r) and data section of resource fork size (size-rd) of a macbinary file """
183
183
184
184
if not file_byte_stream :
185
185
return file_byte_stream
@@ -189,10 +189,10 @@ def macbin_get_resfork_data(file_byte_stream):
189
189
(rsrclen ,) = struct .unpack (">I" , file_byte_stream [0x57 :0x5B ])
190
190
191
191
resoure_fork_offset = 128 + datalen_padded
192
- data_offset = int .from_bytes (file_byte_stream [resoure_fork_offset + 0 : resoure_fork_offset + 4 ])
193
- data_length = int .from_bytes (file_byte_stream [resoure_fork_offset + 8 : resoure_fork_offset + 12 ])
192
+ rd_offset = int .from_bytes (file_byte_stream [resoure_fork_offset + 0 : resoure_fork_offset + 4 ])
193
+ rd_length = int .from_bytes (file_byte_stream [resoure_fork_offset + 8 : resoure_fork_offset + 12 ])
194
194
195
- return (file_byte_stream [resoure_fork_offset + data_offset : resoure_fork_offset + data_offset + data_length ], data_length )
195
+ return (file_byte_stream [resoure_fork_offset + rd_offset : resoure_fork_offset + rd_offset + rd_length ], datalen , rsrclen , rd_length )
196
196
197
197
def macbin_get_datafork (file_byte_stream ):
198
198
if not file_byte_stream :
@@ -222,7 +222,7 @@ def is_appledouble(file_byte_stream):
222
222
return True
223
223
224
224
def appledouble_get_resfork_data (file_byte_stream ):
225
- """ Returns the resource fork's data section as bytes of an appledouble file as well as its size """
225
+ """ Returns the resource fork's data section as bytes, size of resource fork (size-r) and size of data section of resource fork ( size-rd) of an appledouble file """
226
226
227
227
entry_count = read_be_16 (file_byte_stream [24 :])
228
228
for entry in range (entry_count ):
@@ -233,13 +233,13 @@ def appledouble_get_resfork_data(file_byte_stream):
233
233
234
234
if id == 2 :
235
235
resource_fork_stream = file_byte_stream [offset :offset + length ]
236
- data_offset = int .from_bytes (resource_fork_stream [0 :4 ])
237
- data_length = int .from_bytes (resource_fork_stream [8 :12 ])
236
+ rd_offset = int .from_bytes (resource_fork_stream [0 :4 ])
237
+ rd_length = int .from_bytes (resource_fork_stream [8 :12 ])
238
238
239
- return (resource_fork_stream [data_offset : data_offset + data_length ], data_length )
239
+ return (resource_fork_stream [rd_offset : rd_offset + rd_length ], length , rd_length )
240
240
241
241
def appledouble_get_datafork (filepath , fileinfo ):
242
- """ Returns data fork's content as bytes of appledouble file if found, otherwise empty byte string """
242
+ """ Returns data fork's content as bytes and size of data fork of an appledouble file. """
243
243
try :
244
244
index = filepath .index ("__MACOSX" )
245
245
except ValueError :
@@ -253,80 +253,88 @@ def appledouble_get_datafork(filepath, fileinfo):
253
253
254
254
try :
255
255
with open (data_fork_path , "rb" ) as f :
256
- return f .read ()
256
+ data = f .read ()
257
+ return (data , len (data ))
257
258
except (FileNotFoundError , IsADirectoryError ):
258
259
return b''
259
260
260
261
def raw_rsrc_get_datafork (filepath ):
261
- """ Returns the data fork's content as bytes corresponding to raw rsrc file. """
262
+ """ Returns the data fork's content as bytes and size of the data fork corresponding to raw rsrc file. """
262
263
try :
263
264
with open (filepath [:- 5 ]+ ".data" , "rb" ) as f :
264
- return f .read ()
265
+ data = f .read ()
266
+ return (data , len (data ))
265
267
except (FileNotFoundError , IsADirectoryError ):
266
268
return b''
267
269
268
270
def raw_rsrc_get_resource_fork_data (filepath ):
269
- """ Returns the resource fork's data section as bytes of a raw rsrc file as well as its size """
271
+ """ Returns the resource fork's data section as bytes, size of resource fork (size-r) and size of data section of resource fork ( size-rd) of a raw rsrc file. """
270
272
with open (filepath , "rb" ) as f :
271
273
resource_fork_stream = f .read ()
272
- data_offset = int .from_bytes (resource_fork_stream [0 :4 ])
273
- data_length = int .from_bytes (resource_fork_stream [8 :12 ])
274
+ resource_fork_len = len (resource_fork_stream )
275
+ rd_offset = int .from_bytes (resource_fork_stream [0 :4 ])
276
+ rd_length = int .from_bytes (resource_fork_stream [8 :12 ])
274
277
275
- return (resource_fork_stream [data_offset : data_offset + data_length ], data_length )
278
+ return (resource_fork_stream [rd_offset : rd_offset + rd_length ], resource_fork_len , rd_length )
276
279
277
280
def actual_mac_fork_get_data_fork (filepath ):
278
- """ Returns the data fork's content as bytes if the actual mac fork exists """
281
+ """ Returns the data fork's content as bytes and its size if the actual mac fork exists """
279
282
try :
280
283
with open (filepath , "rb" ) as f :
281
- return f .read ()
284
+ data = f .read ()
285
+ return (data , len (data ))
282
286
except (FileNotFoundError , IsADirectoryError ):
283
287
return b''
284
288
285
289
def actual_mac_fork_get_resource_fork_data (filepath ):
286
- """ Returns the resource fork's data section as bytes of the actual mac fork as well as its size """
290
+ """ Returns the resource fork's data section as bytes, size of resource fork (size-r) and size of data section of resource fork ( size-rd) of the actual mac fork. """
287
291
resource_fork_path = os .path .join (filepath , "..namedfork" , "rsrc" )
288
292
with open (resource_fork_path , "rb" ) as f :
289
293
resource_fork_stream = f .read ()
290
- data_offset = int .from_bytes (resource_fork_stream [0 :4 ])
291
- data_length = int .from_bytes (resource_fork_stream [8 :12 ])
294
+ resource_fork_len = len (resource_fork_stream )
295
+ rd_offset = int .from_bytes (resource_fork_stream [0 :4 ])
296
+ rd_length = int .from_bytes (resource_fork_stream [8 :12 ])
292
297
293
- return (resource_fork_stream [data_offset : data_offset + data_length ], data_length )
298
+ return (resource_fork_stream [rd_offset : rd_offset + rd_length ], resource_fork_len , rd_length )
294
299
295
- def file_checksum (filepath , alg , size , file_info ):
296
- cur_file_size = 0
300
+ def file_checksum (filepath , alg , custom_checksum_size , file_info ):
297
301
with open (filepath , "rb" ) as f :
298
302
if file_info [0 ] == FileType .NON_MAC :
299
- return (create_checksum_pairs (checksum (f , alg , size , filepath ), alg , size ), filesize (filepath ))
303
+ return (create_checksum_pairs (checksum (f , alg , custom_checksum_size , filepath ), alg , custom_checksum_size ), filesize (filepath ), 0 , 0 )
300
304
301
305
# Processing mac files
302
306
res = []
303
307
resfork = b''
304
308
datafork = b''
305
309
file_data = f .read ()
306
310
311
+ size = 0
312
+ size_r = 0
313
+ size_rd = 0
314
+
307
315
if file_info [0 ] == FileType .MAC_BINARY :
308
- (resfork , cur_file_size ) = macbin_get_resfork_data (file_data )
316
+ (resfork , size , size_r , size_rd ) = macbin_get_resfork_data (file_data )
309
317
datafork = macbin_get_datafork (file_data )
310
318
elif file_info [0 ] in {FileType .APPLE_DOUBLE_DOT_ , FileType .APPLE_DOUBLE_RSRC , FileType .APPLE_DOUBLE_MACOSX }:
311
- (resfork , cur_file_size ) = appledouble_get_resfork_data (file_data )
312
- datafork = appledouble_get_datafork (filepath , file_info )
319
+ (resfork , size_r , size_rd ) = appledouble_get_resfork_data (file_data )
320
+ ( datafork , size ) = appledouble_get_datafork (filepath , file_info )
313
321
elif file_info [0 ] == FileType .RAW_RSRC :
314
- (resfork , cur_file_size ) = raw_rsrc_get_resource_fork_data (filepath )
315
- datafork = raw_rsrc_get_datafork (filepath )
322
+ (resfork , size_r , size_rd ) = raw_rsrc_get_resource_fork_data (filepath )
323
+ datafork , size = raw_rsrc_get_datafork (filepath )
316
324
elif file_info [0 ] == FileType .ACTUAL_FORK_MAC :
317
- (resfork , cur_file_size ) = actual_mac_fork_get_resource_fork_data (filepath )
318
- datafork = actual_mac_fork_get_data_fork (filepath )
325
+ (resfork , size_r , size_rd ) = actual_mac_fork_get_resource_fork_data (filepath )
326
+ ( datafork , size ) = actual_mac_fork_get_data_fork (filepath )
319
327
320
- hashes = checksum (resfork , alg , size , filepath )
328
+ hashes = checksum (resfork , alg , custom_checksum_size , filepath )
321
329
prefix = 'r'
322
330
if len (resfork ):
323
- res .extend (create_checksum_pairs (hashes , alg , size , prefix ))
331
+ res .extend (create_checksum_pairs (hashes , alg , custom_checksum_size , prefix ))
324
332
325
- hashes = checksum (datafork , alg , size , filepath )
333
+ hashes = checksum (datafork , alg , custom_checksum_size , filepath )
326
334
prefix = 'd'
327
- res .extend (create_checksum_pairs (hashes , alg , size , prefix ))
335
+ res .extend (create_checksum_pairs (hashes , alg , custom_checksum_size , prefix ))
328
336
329
- return (res , cur_file_size )
337
+ return (res , size , size_r , size_rd )
330
338
331
339
def create_checksum_pairs (hashes , alg , size , prefix = None ):
332
340
res = []
@@ -571,7 +579,8 @@ def filter_files_by_timestamp(files, limit_timestamps_date):
571
579
"""
572
580
573
581
filtered_file_map = defaultdict (str )
574
- user_date = validate_date (limit_timestamps_date )
582
+ if limit_timestamp_date is not None :
583
+ user_date = validate_date (limit_timestamps_date )
575
584
today = date .today ()
576
585
577
586
for filepath in files :
@@ -595,8 +604,8 @@ def create_dat_file(hash_of_dirs, path, checksum_size=0):
595
604
# Game files
596
605
for hash_of_dir in hash_of_dirs :
597
606
file .write ("game (\n " )
598
- for filename , (hashes , filesize , timestamp ) in hash_of_dir .items ():
599
- data = f"name \" { filename } \" size { filesize } timestamp { timestamp } "
607
+ for filename , (hashes , size , size_r , size_rd , timestamp ) in hash_of_dir .items ():
608
+ data = f"name \" { filename } \" size { size } size-r { size_r } size-rd { size_rd } timestamp { timestamp } "
600
609
for key , value in hashes :
601
610
data += f" { key } { value } "
602
611
0 commit comments