<commit_before>//
//  URKArchive.mm
//  UnrarKit
//
//

#import "URKArchive.h"
#import "URKFileInfo.h"
#import "NSString+UnrarKit.h"

#import "rar.hpp"


NSString *URKErrorDomain = @"URKErrorDomain";


@interface URKArchive ()

- (id)initWithFile:(NSURL *)fileURL NS_DESIGNATED_INITIALIZER;

@property (strong) NSData *fileBookmark;
@property (strong) void(^bufferedReadBlock)(NSData *dataChunk);

@end


@implementation URKArchive



#pragma mark - Convenience Methods


+ (URKArchive *)rarArchiveAtPath:(NSString *)filePath
{
    return [[URKArchive alloc] initWithFile:[NSURL fileURLWithPath:filePath]];
}

+ (URKArchive *)rarArchiveAtURL:(NSURL *)fileURL
{
    return [[URKArchive alloc] initWithFile:fileURL];
}

+ (URKArchive *)rarArchiveAtPath:(NSString *)filePath password:(NSString *)password
{
    return [[URKArchive alloc] initWithFile:[NSURL fileURLWithPath:filePath]
                                   password:password];
}

+ (URKArchive *)rarArchiveAtURL:(NSURL *)fileURL password:(NSString *)password
{
    return [[URKArchive alloc] initWithFile:fileURL password:password];
}



#pragma mark - Initializers


- (id)initWithFile:(NSURL *)fileURL
{
    if ((self = [super init])) {
        NSError *error = nil;
        self.fileBookmark = [fileURL bookmarkDataWithOptions:0
                              includingResourceValuesForKeys:@[]
                                               relativeToURL:nil
                                                       error:&error];
        
        if (error) {
            NSLog(@"Error creating bookmark to RAR archive: %@", error);
        }
    }
    
	return self;
};

- (id)initWithFile:(NSURL *)fileURL password:(<PASSWORD>*)password
{
	if ((self = [self initWithFile:fileURL])) {
        self.password = password;
    }
    
    return self;
}


#pragma mark - Properties


- (NSURL *)fileURL
{
    BOOL bookmarkIsStale = NO;
    NSError *error = nil;
    
    NSURL *result = [NSURL URLByResolvingBookmarkData:self.fileBookmark
                                              options:0
                                        relativeToURL:nil
                                  bookmarkDataIsStale:&bookmarkIsStale
                                                error:&error];
    
    if (error) {
        NSLog(@"Error resolving bookmark to RAR archive: %@", error);
        return nil;<commit_msg>Refactored initializers<commit_after>//
//  URKArchive.mm
//  UnrarKit
//
//

#import "URKArchive.h"
#import "URKFileInfo.h"
#import "NSString+UnrarKit.h"

#import "rar.hpp"


NSString *URKErrorDomain = @"URKErrorDomain";


@interface URKArchive ()

- (instancetype)initWithFile:(NSURL *)fileURL password:(NSString*)password NS_DESIGNATED_INITIALIZER;

@property (strong) NSData *fileBookmark;
@property (strong) void(^bufferedReadBlock)(NSData *dataChunk);

@end


@implementation URKArchive



#pragma mark - Convenience Methods


+ (URKArchive *)rarArchiveAtPath:(NSString *)filePath
{
    return [[URKArchive alloc] initWithFile:[NSURL fileURLWithPath:filePath]];
}

+ (URKArchive *)rarArchiveAtURL:(NSURL *)fileURL
{
    return [[URKArchive alloc] initWithFile:fileURL];
}

+ (URKArchive *)rarArchiveAtPath:(NSString *)filePath password:(NSString *)password
{
    return [[URKArchive alloc] initWithFile:[NSURL fileURLWithPath:filePath]
                                   password:password];
}

+ (URKArchive *)rarArchiveAtURL:(NSURL *)fileURL password:(NSString *)password
{
    return [[URKArchive alloc] initWithFile:fileURL password:password];
}



#pragma mark - Initializers


- (instancetype)initWithFile:(NSURL *)fileURL
{
    return [self initWithFile:fileURL password:nil];
}

- (instancetype)initWithFile:(NSURL *)fileURL password:(NSString*)password
{
    if ((self = [super init])) {
        NSError *error = nil;
        self.fileBookmark = [fileURL bookmarkDataWithOptions:0
                              includingResourceValuesForKeys:@[]
                                               relativeToURL:nil
                                                       error:&error];
        self.password = password;

        if (error) {
            NSLog(@"Error creating bookmark to RAR archive: %@", error);
        }
    }
    
    return self;
}


#pragma mark - Properties


- (NSURL *)fileURL
{
    BOOL bookmarkIsStale = NO;
    NSError *error = nil;
    
    NSURL *result = [NSURL URLByResolvingBookmarkData:self.fileBookmark
                                              options:0
                                        relativeToURL:nil
                                  bookmarkDataIsStale:&bookmarkIsStale
                                                error:&error];
    
    if (error) {
        NSLog(@"Error resolving bookmark to RAR archive: %@", error);
        return nil;
{'fraction_non_alphanumeric': 0.11078534031413613, 'fraction_numerical': 0.000837696335078534, 'mean_word_length': 2.3375262054507338, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7109981', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1336, 'n_words': 279}