{"id":16697487,"url":"https://github.com/thisandagain/storage","last_synced_at":"2025-05-08T21:21:07.049Z","repository":{"id":3705111,"uuid":"4776479","full_name":"thisandagain/storage","owner":"thisandagain","description":"An iOS library for fast, easy, and safe threaded disk I/O.","archived":false,"fork":false,"pushed_at":"2017-02-09T22:29:26.000Z","size":87,"stargazers_count":256,"open_issues_count":0,"forks_count":23,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-02-09T00:28:30.550Z","etag":null,"topics":["disk","io","nsdata","objective-c","storage","uiimage"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thisandagain.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-25T00:30:43.000Z","updated_at":"2025-02-08T12:36:56.000Z","dependencies_parsed_at":"2022-09-05T13:20:55.519Z","dependency_job_id":null,"html_url":"https://github.com/thisandagain/storage","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisandagain%2Fstorage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisandagain%2Fstorage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisandagain%2Fstorage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisandagain%2Fstorage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thisandagain","download_url":"https://codeload.github.com/thisandagain/storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238044093,"owners_count":19407128,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["disk","io","nsdata","objective-c","storage","uiimage"],"created_at":"2024-10-12T17:47:59.234Z","updated_at":"2025-02-10T02:07:34.880Z","avatar_url":"https://github.com/thisandagain.png","language":"Objective-C","readme":"## Storage\n#### Persist all the things! Wheee!\n\nIn attempting to keep things [DRY](http://en.wikipedia.org/wiki/Don't_repeat_yourself), EDStorage was created to address the fair amount of boilerplate that often gets created to deal with writing data to disk within iOS applications in a performant manner. Disk I/O within iOS is synchronous and so much of this boilerplate is often written to improve performance by moving I/O to a background thread. EDStorage accomplishes this by transforming each write instance into a `NSOperation` which is managed by a single `NSOperationQueue`. All of this is done in the background while providing high-level methods to the user via categories. \n\n**EDStorage strives to provide three things:**\n- An abstract interface based on categories that makes persisting data to disk simple.\n- A highly generic management interface that makes extending EDStorage equally simple.\n- Speed and safety.\n\n## Basic Use\nThe easiest way to get going with EDStorage is to take a look at the included example application. The Xcode project file can be found in `example \u003e storage.xcodeproj`.\n\nIn order to include EDStorage in your project, you'll want to add the entirety of the `EDStorage` directory to your project. EDStorage is built on top of foundation libraries and so no additional frameworks are needed. To bring in all of the included storage categories, simply:\n\n```objective-c\n#import \"EDStorage.h\"\n```\n\nEach category has a slightly different interface depending on the needs of a specific class, but to use a common example, let's look at how to persist a UIImage to the application cache directory:\n\n```objective-c\n- (void)doSomething\n{\n    UIImage *image = [UIImage imageNamed:@\"keyboardCat.png\"];\n    \n    [image persistToCache:^(NSURL *url, NSUInteger size) {\n        NSLog(@\"FTW!: %@ | %d bytes\", url, size);\n    } failure:^(NSError *error) {\n        NSLog(@\"UH OH: %@\", error);\n    }];\n}\n```\n\nPersisting to the temporary and documents application directories is equaly simple:\n\n```objective-c\n[image persistToTemp:^(NSURL *url, NSUInteger size) {\n    NSLog(@\"FTW!: %@ | %d bytes\", url, size);\n} failure:^(NSError *error) {\n    NSLog(@\"UH OH: %@\", error);\n}];\n```\n\n```objective-c\n[image persistToDocuments:^(NSURL *url, NSUInteger size) {\n    NSLog(@\"FTW!: %@ | %d bytes\", url, size);\n} failure:^(NSError *error) {\n    NSLog(@\"UH OH: %@\", error);\n}];\n```\n\n## Implementing A Storage Category\n`EDStorageManager` provides a single block method for interfacing with categories:\n\n```objective-c\n- (void)persistData:(id)data withExtension:(NSString *)ext toLocation:(Location)location success:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure;\n```\n\nCategories simply abstract the process of calling this method on `EDStorageManager` by handling conversion of the class instance into a NSData object. See the `NSData+Storage` implementation  For example, the storage category for UIImage simply passes self into NSData by calling `UIImageJPEGRepresentation()`. \n\n**If you create a category that you find useful, please let me know! Pull requests are welcome.**\n\n---\n\n## Locations\n```objective-c\nEDStorageDirectoryCache\nEDStorageDirectoryTemp\nEDStorageDirectoryDocuments\n```\n\n## NSData+Storage Methods\n```objective-c\n- (void)persistToCacheWithExtension:(NSString *)extension success:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure;\n- (void)persistToTempWithExtension:(NSString *)extension success:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure;\n- (void)persistToDocumentsWithExtension:(NSString *)extension success:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure;\n```\n\n## NSDictionary+Storage Methods\n```objective-c\n- (void)persistToCache:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure;\n- (void)persistToTemp:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure;\n- (void)persistToDocuments:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure;\n```\n\n## UIImage+Storage Methods\n```objective-c\n- (void)persistToCache:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure;\n- (void)persistToTemp:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure;\n- (void)persistToDocuments:(void (^)(NSURL *url, NSUInteger size))success failure:(void (^)(NSError *error))failure;\n```\n\n---\n\n## iOS Support\nEDStorage is tested on iOS 5 and up. Older versions of iOS may work but are not currently supported.\n\n## ARC\nEDStorage as of v0.2.0 is built using ARC. If you are including EDStorage in a project that **does not** use [Automatic Reference Counting (ARC)](http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html), you will need to set the `-fobjc-arc` compiler flag on all of the EDStorage source files. To do this in Xcode, go to your active target and select the \"Build Phases\" tab. Now select all EDStorage source files, press Enter, insert `-fobjc-arc` and then \"Done\" to enable ARC for EDStorage.\n","funding_links":[],"categories":["uiimage"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthisandagain%2Fstorage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthisandagain%2Fstorage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthisandagain%2Fstorage/lists"}