aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPFileHandle.h
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-04-12 00:08:40 +0000
committerrowanbeentje <rowan@beent.je>2010-04-12 00:08:40 +0000
commitebfd8ca1dac81755451a22e364daa851992b386e (patch)
treeebc4ec3dbdbdb8e72f747d849a85a6a497bf6ea4 /Source/SPFileHandle.h
parentcd9e9490ce6f073514cab18731cc0553f1c750d1 (diff)
downloadsequelpro-ebfd8ca1dac81755451a22e364daa851992b386e.tar.gz
sequelpro-ebfd8ca1dac81755451a22e364daa851992b386e.tar.bz2
sequelpro-ebfd8ca1dac81755451a22e364daa851992b386e.zip
Add a new SPFileHandle class to support gzip compression and writing on a background thread, and integrate for SQL import:
- Implement streaming reading of gzip-compressed files for SQL import - Support exporting SQL dumps into a gzip-compressed file - SPFileHandle supports the most-used subset of NSFileHandle commands for easy integration - Integrate zlib 1.2.4 for improved gzip streaming performance (and support for custom buffer sizes and file offset positions) This implements Issue #571 .
Diffstat (limited to 'Source/SPFileHandle.h')
-rw-r--r--Source/SPFileHandle.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/Source/SPFileHandle.h b/Source/SPFileHandle.h
new file mode 100644
index 00000000..f614d403
--- /dev/null
+++ b/Source/SPFileHandle.h
@@ -0,0 +1,78 @@
+//
+// SPFileHandle.h
+// sequel-pro
+//
+// Created by Rowan Beentje on 05/04/2010.
+// Copyright 2010 Arboreal. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@interface SPFileHandle : NSObject {
+ void *wrappedFile;
+ char *wrappedFilePath;
+
+ NSMutableData *buffer;
+ NSUInteger bufferDataLength;
+ NSUInteger bufferPosition;
+ BOOL endOfFile;
+ pthread_mutex_t bufferLock;
+ NSThread *processingThread;
+
+ int fileMode;
+ BOOL dataWritten;
+ BOOL fileIsClosed;
+ BOOL useGzip;
+}
+
+
+#pragma mark -
+#pragma mark Class methods
+
++ (id) fileHandleForReadingAtPath:(NSString *)path;
++ (id) fileHandleForWritingAtPath:(NSString *)path;
++ (id) fileHandleForPath:(NSString *)path mode:(int)mode;
+
+#pragma mark -
+#pragma mark Initialisation
+
+// Returns a file handle initialised with a file
+- (id) initWithFile:(void *)theFile fromPath:(const char *)path mode:(int)mode;
+
+
+#pragma mark -
+#pragma mark Data reading
+
+// Reads data up to a specified number of bytes from the file
+- (NSMutableData *) readDataOfLength:(NSUInteger)length;
+
+// Returns the data to the end of the file
+- (NSMutableData *) readDataToEndOfFile;
+
+// Returns the on-disk (raw) length of data read so far - can be used in progress bars
+- (NSUInteger) realDataReadLength;
+
+#pragma mark -
+#pragma mark Data writing
+
+// Set whether data should be written as gzipped data (defaults to NO on a fresh object)
+- (void) setShouldWriteWithGzipCompression:(BOOL)useGzip;
+
+// Write the provided data to the file
+- (void) writeData:(NSData *)data;
+
+// Ensures any buffers are written to disk
+- (void) synchronizeFile;
+
+// Prevents further access to the file
+- (void) closeFile;
+
+
+#pragma mark -
+#pragma mark File information
+
+// Returns whether gzip compression is enabled on the file
+- (BOOL) isCompressed;
+
+
+@end