forked from alinebee/Boxer
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathBXFilesystem.h
76 lines (55 loc) · 3.17 KB
/
BXFilesystem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
Boxer is copyright 2011 Alun Bestor and contributors.
Boxer is released under the GNU General Public License 2.0. A full copy of this license can be
found in this XCode project at Resources/English.lproj/BoxerHelp/pages/legalese.html, or read
online at [http://www.gnu.org/licenses/gpl-2.0.txt].
*/
#import <Foundation/Foundation.h>
typedef BOOL (^BXDirectoryEnumeratorErrorHandler)(NSURL *url, NSError *error);
@protocol BXFilesystemEnumerator;
@protocol BXFilesystem <NSObject>
//Resolves a URL to/from a filesystem representation.
- (const char *) fileSystemRepresentationForURL: (NSURL *)URL;
- (NSURL *) URLFromFileSystemRepresentation: (const char *)representation;
//Returns an enumerator for the specified URL, that will return NSURL objects.
//This enumerator should respect the same parameters as NSFileManager's
//enumeratorAtURL:includingPropertiesForKeys:options:errorHandler: method.
- (id <BXFilesystemEnumerator>) enumeratorAtURL: (NSURL *)URL
includingPropertiesForKeys: (NSArray *)keys
options: (NSDirectoryEnumerationOptions)mask
errorHandler: (BXDirectoryEnumeratorErrorHandler)errorHandler;
#pragma mark -
#pragma mark Creating, deleting and accessing files.
//Returns an open file handle for the resource represented by the specified URL,
//using the specified access mode (in the standard fopen format).
//Returns nil and populates outError on failure.
- (FILE *) openFileAtURL: (NSURL *)URL
inMode: (const char *)accessMode
error: (NSError **)outError;
//Deletes the file or directory at the specified URL.
//Returns YES if the operation was successful, or NO and populates outError on failure.
- (BOOL) removeItemAtURL: (NSURL *)URL error: (NSError **)outError;
//Copy/move an item from the specified source URL to the specified destination.
//Returns YES if the operation was successful, or NO and populates outError on failure.
- (BOOL) copyItemAtURL: (NSURL *)fromURL toURL: (NSURL *)toURL error: (NSError **)outError;
- (BOOL) moveItemAtURL: (NSURL *)fromURL toURL: (NSURL *)toURL error: (NSError **)outError;
//Returns whether the item at the specified URL exists.
//If isDirectory is provided, this will be populated with YES if the URL represents a directory
//or NO otherwise.
- (BOOL) fileExistsAtURL: (NSURL *)URL isDirectory: (BOOL *)isDirectory;
//Creates a new directory at the specified URL, optionally creating any missing directories in-between.
//Returns YES if the directory or directories were created, or NO on failure.
- (BOOL) createDirectoryAtURL: (NSURL *)URL
withIntermediateDirectories: (BOOL)createIntermediates
error: (NSError **)outError;
@end
//A protocol for NSDirectoryEnumerator-alike objects. See that class for general behaviour.
@protocol BXFilesystemEnumerator <NSObject, NSFastEnumeration>
- (void) skipDescendants;
- (NSUInteger) level;
- (NSURL *) nextObject;
//Returns the filesystem representation of the specified URL, or NULL if this is not applicable.
- (const char *) fileSystemRepresentationForURL: (NSURL *)URL;
//Reset the enumerator back to the first entry.
- (void) reset;
@end