ObjFW  Check-in [780132a941]

Overview
Comment:ofarc: Add support for creating Zoo archives
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 780132a941c6b69d93eccb93f2c9539d6bd814c919c85bf486dc5356881dcb96
User & Date: js on 2024-03-03 19:54:53
Other Links: manifest | tags
Context
2024-03-03
20:03
OFLHAArchive: Don't default to ISO 8859-1 check-in: b8afc53cce user: js tags: trunk
19:54
ofarc: Add support for creating Zoo archives check-in: 780132a941 user: js tags: trunk
19:42
Rename schemes for archive IRI handlers check-in: 13f0321eff user: js tags: trunk
Changes

Modified src/OFZooArchive.h from [67f1c555c6] to [f7452af878].

48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
 */
@property (nonatomic) OFStringEncoding encoding;

/**
 * @brief Creates a new OFZooArchive object with the specified stream.
 *
 * @param stream A stream from which the Zoo archive will be read.
 *		 For read mode, this needs to be an OFSeekableStream.

 * @param mode The mode for the Zoo file. Valid modes are "r" for reading and
 *	       "w" for creating a new file.
 * @return A new, autoreleased OFZooArchive
 */
+ (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode;

/**







|
>







48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 */
@property (nonatomic) OFStringEncoding encoding;

/**
 * @brief Creates a new OFZooArchive object with the specified stream.
 *
 * @param stream A stream from which the Zoo archive will be read.
 *		 This needs to be an OFSeekableStream. For writing, the stream
 *		 needs to support both reading and writing at the same time.
 * @param mode The mode for the Zoo file. Valid modes are "r" for reading and
 *	       "w" for creating a new file.
 * @return A new, autoreleased OFZooArchive
 */
+ (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode;

/**
83
84
85
86
87
88
89
90

91
92
93
94
95
96
97
- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated OFZooArchive object with the
 *	  specified stream.
 *
 * @param stream A stream from which the Zoo archive will be read.
 *		 For read mode, this needs to be an OFSeekableStream.

 * @param mode The mode for the Zoo file. Valid modes are "r" for reading and
 *	       "w" for creating a new file.
 * @return An initialized OFZooArchive
 */
- (instancetype)initWithStream: (OFStream *)stream
			  mode: (OFString *)mode OF_DESIGNATED_INITIALIZER;








|
>







84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
- (instancetype)init OF_UNAVAILABLE;

/**
 * @brief Initializes an already allocated OFZooArchive object with the
 *	  specified stream.
 *
 * @param stream A stream from which the Zoo archive will be read.
 *		 This needs to be an OFSeekableStream. For writing, the stream
 *		 needs to support both reading and writing at the same time.
 * @param mode The mode for the Zoo file. Valid modes are "r" for reading and
 *	       "w" for creating a new file.
 * @return An initialized OFZooArchive
 */
- (instancetype)initWithStream: (OFStream *)stream
			  mode: (OFString *)mode OF_DESIGNATED_INITIALIZER;

Modified utils/ofarc/OFArc.m from [b277cdf39b] to [4801a33bf2].

508
509
510
511
512
513
514
515

516
517
518
519
520
521
522

	switch (mode) {
	case 'a':
		modeString = @"a";
		fileModeString = @"r+";
		break;
	case 'c':
		modeString = fileModeString = @"w";

		break;
	case 'l':
	case 'p':
	case 'x':
		modeString = fileModeString = @"r";
		break;
	default:







|
>







508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523

	switch (mode) {
	case 'a':
		modeString = @"a";
		fileModeString = @"r+";
		break;
	case 'c':
		modeString = @"w";
		fileModeString = @"w+";
		break;
	case 'l':
	case 'p':
	case 'x':
		modeString = fileModeString = @"r";
		break;
	default:

Modified utils/ofarc/ZooArchive.m from [5bee585379] to [116b81ed76].

430
431
432
433
434
435
436










































































































437
	for (OFString *file in files) {
		[OFStdErr writeLine: OF_LOCALIZED(@"file_not_in_archive",
		    @"File %[file] is not in the archive!",
		    @"file", file)];
		app->_exitStatus = 1;
	}
}










































































































@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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
	for (OFString *file in files) {
		[OFStdErr writeLine: OF_LOCALIZED(@"file_not_in_archive",
		    @"File %[file] is not in the archive!",
		    @"file", file)];
		app->_exitStatus = 1;
	}
}

- (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files
{
	OFFileManager *fileManager = [OFFileManager defaultManager];

	if (files.count < 1) {
		[OFStdErr writeLine: OF_LOCALIZED(@"add_no_file_specified",
		    @"Need one or more files to add!")];
		app->_exitStatus = 1;
		return;
	}

	for (OFString *fileName in files) {
		void *pool = objc_autoreleasePoolPush();
		OFFileAttributes attributes;
		OFFileAttributeType type;
		OFMutableZooArchiveEntry *entry;
		OFStream *output;

		if (app->_outputLevel >= 0)
			[OFStdOut writeString: OF_LOCALIZED(@"adding_file",
			    @"Adding %[file]...",
			    @"file", fileName)];

		attributes = [fileManager attributesOfItemAtPath: fileName];
		type = attributes.fileType;

		if ([type isEqual: OFFileTypeDirectory]) {
			if (app->_outputLevel >= 0) {
				[OFStdOut writeString: @"\r"];
				[OFStdOut writeLine: OF_LOCALIZED(
				    @"adding_file_skipped",
				    @"Adding %[file]... skipped",
				    @"file", fileName)];
			}

			continue;
		}

		entry = [OFMutableZooArchiveEntry entryWithFileName: fileName];
		entry.timeZone = [OFNumber numberWithFloat: 0];
		entry.modificationDate = attributes.fileModificationDate;
#ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS
		entry.POSIXPermissions =
		    [attributes objectForKey: OFFilePOSIXPermissions];
#endif

		output = [_archive streamForWritingEntry: entry];

		if ([type isEqual: OFFileTypeRegular]) {
			unsigned long long written = 0;
			unsigned long long size = attributes.fileSize;
			int8_t percent = -1, newPercent;

			OFFile *input = [OFFile fileWithPath: fileName
							mode: @"r"];

			while (!input.atEndOfStream) {
				ssize_t length = [app
				    copyBlockFromStream: input
					       toStream: output
					       fileName: fileName];

				if (length < 0) {
					app->_exitStatus = 1;
					goto outer_loop_end;
				}

				written += length;
				newPercent = (written == size
				    ? 100 : (int8_t)(written * 100 / size));

				if (app->_outputLevel >= 0 &&
				    percent != newPercent) {
					OFString *percentString;

					percent = newPercent;
					percentString = [OFString
					    stringWithFormat: @"%3u", percent];

					[OFStdOut writeString: @"\r"];
					[OFStdOut writeString: OF_LOCALIZED(
					    @"adding_file_percent",
					    @"Adding %[file]... %[percent]%",
					    @"file", fileName,
					    @"percent", percentString)];
				}
			}
		}

		if (app->_outputLevel >= 0) {
			[OFStdOut writeString: @"\r"];
			[OFStdOut writeLine: OF_LOCALIZED(
			    @"adding_file_done",
			    @"Adding %[file]... done",
			    @"file", fileName)];
		}

		[output close];

outer_loop_end:
		objc_autoreleasePoolPop(pool);
	}

	[_archive close];
}
@end

Modified utils/ofarc/localization/de.json from [0366ea8180] to [deba1f0d7e].

144
145
146
147
148
149
150

151
    ],
    add_no_file_specified: [
        "Benötige eine oder mehrere Dateien zum Hinzufügen!"
    ],
    adding_file: "Füge %[file] hinzu...",
    adding_file_percent: "Füge %[file] hinzu... %[percent]%",
    adding_file_done: "Füge %[file] hinzu... fertig",

}







>

144
145
146
147
148
149
150
151
152
    ],
    add_no_file_specified: [
        "Benötige eine oder mehrere Dateien zum Hinzufügen!"
    ],
    adding_file: "Füge %[file] hinzu...",
    adding_file_percent: "Füge %[file] hinzu... %[percent]%",
    adding_file_done: "Füge %[file] hinzu... fertig",
    adding_file_skipped: "Füge %[file] hinzu... übersprungen",
}