ObjFW
 All Classes Functions Variables
Instance Methods | Class Methods | List of all members
OFFile Class Reference

A class which provides functions to read, write and manipulate files. More...

#import <OFFile.h>

Inheritance diagram for OFFile:
OFSeekableStream OFStream OFObject <OFCopying> <OFObject>

Instance Methods

(id) - initWithPath:mode:
 Initializes an already allocated OFFile.
 
(id) - initWithFileDescriptor:
 Initializes an already allocated OFFile.
 
- Instance Methods inherited from OFSeekableStream
(void) - seekToOffset:
 Seeks to the specified absolute offset.
 
(off_t) - seekForwardWithOffset:
 Seeks to the specified offset, relative to the current location.
 
(off_t) - seekToOffsetRelativeToEnd:
 Seeks to the specified offset, relative to the end of the stream.
 
(void) - lowlevelSeekToOffset:
 Seek the stream on the lowlevel.
 
(off_t) - lowlevelSeekForwardWithOffset:
 Seek the stream on the lowlevel.
 
(off_t) - lowlevelSeekToOffsetRelativeToEnd:
 Seek the stream on the lowlevel.
 
- Instance Methods inherited from OFStream
(BOOL) - isAtEndOfStream
 Returns a boolean whether the end of the stream has been reached.
 
(size_t) - readIntoBuffer:length:
 Reads at most size bytes from the stream into a buffer.
 
(void) - readIntoBuffer:exactLength:
 Reads exactly the specified length bytes from the stream into a buffer.
 
(void) - asyncReadIntoBuffer:length:target:selector:
 Asyncronously reads at most size bytes from the stream into a buffer.
 
(void) - asyncReadIntoBuffer:exactLength:target:selector:
 Asyncronously reads exactly the specified length bytes from the stream into a buffer.
 
(uint8_t) - readInt8
 Reads a uint8_t from the stream.
 
(uint16_t) - readBigEndianInt16
 Reads a uint16_t from the stream which is encoded in big endian.
 
(uint32_t) - readBigEndianInt32
 Reads a uint32_t from the stream which is encoded in big endian.
 
(uint64_t) - readBigEndianInt64
 Reads a uint64_t from the stream which is encoded in big endian.
 
(float) - readBigEndianFloat
 Reads a float from the stream which is encoded in big endian.
 
(double) - readBigEndianDouble
 Reads a double from the stream which is encoded in big endian.
 
(size_t) - readBigEndianInt16sIntoBuffer:count:
 Reads the specified number of uint16_ts from the stream which are encoded in big endian.
 
(size_t) - readBigEndianInt32sIntoBuffer:count:
 Reads the specified number of uint32_ts from the stream which are encoded in big endian.
 
(size_t) - readBigEndianInt64sIntoBuffer:count:
 Reads the specified number of uint64_ts from the stream which are encoded in big endian.
 
(size_t) - readBigEndianFloatsIntoBuffer:count:
 Reads the specified number of floats from the stream which are encoded in big endian.
 
(size_t) - readBigEndianDoublesIntoBuffer:count:
 Reads the specified number of doubles from the stream which are encoded in big endian.
 
(uint16_t) - readLittleEndianInt16
 Reads a uint16_t from the stream which is encoded in little endian.
 
(uint32_t) - readLittleEndianInt32
 Reads a uint32_t from the stream which is encoded in little endian.
 
(uint64_t) - readLittleEndianInt64
 Reads a uint64_t from the stream which is encoded in little endian.
 
(float) - readLittleEndianFloat
 Reads a float from the stream which is encoded in little endian.
 
(double) - readLittleEndianDouble
 Reads a double from the stream which is encoded in little endian.
 
(size_t) - readLittleEndianInt16sIntoBuffer:count:
 Reads the specified number of uint16_ts from the stream which are encoded in little endian.
 
(size_t) - readLittleEndianInt32sIntoBuffer:count:
 Reads the specified number of uint32_ts from the stream which are encoded in little endian.
 
(size_t) - readLittleEndianInt64sIntoBuffer:count:
 Reads the specified number of uint64_ts from the stream which are encoded in little endian.
 
(size_t) - readLittleEndianFloatsIntoBuffer:count:
 Reads the specified number of floats from the stream which are encoded in little endian.
 
(size_t) - readLittleEndianDoublesIntoBuffer:count:
 Reads the specified number of doubles from the stream which are encoded in little endian.
 
(OFDataArray *) - readDataArrayWithSize:
 Reads the specified number of items with an item size of 1 from the stream and returns them in an OFDataArray.
 
(OFDataArray *) - readDataArrayWithItemSize:count:
 Reads the specified number of items with the specified item size from the stream and returns them in an OFDataArray.
 
(OFDataArray *) - readDataArrayTillEndOfStream
 Returns an OFDataArray with all the remaining data of the stream.
 
(OFString *) - readStringWithLength:
 Reads a string with the specified length from the stream.
 
(OFString *) - readStringWithLength:encoding:
 Reads a string with the specified encoding and length from the stream.
 
(OFString *) - readLine
 Reads until a newline, \0 or end of stream occurs.
 
(OFString *) - readLineWithEncoding:
 Reads with the specified encoding until a newline, \0 or end of stream occurs.
 
(void) - asyncReadLineWithTarget:selector:
 Asyncronously reads until a newline, \0, end of stream or an exception occurs.
 
(void) - asyncReadLineWithEncoding:target:selector:
 Asyncronously reads with the specified encoding until a newline, \0, end of stream or an exception occurs.
 
(OFString *) - tryReadLine
 Tries to read a line from the stream (see readLine) and returns nil if no complete line has been received yet.
 
(OFString *) - tryReadLineWithEncoding:
 Tries to read a line from the stream with the specified encoding (see readLineWithEncoding:) and returns nil if no complete line has been received yet.
 
(OFString *) - readTillDelimiter:
 Reads until the specified string or \0 is found or the end of stream occurs.
 
(OFString *) - readTillDelimiter:encoding:
 Reads until the specified string or \0 is found or the end of stream occurs.
 
(OFString *) - tryReadTillDelimiter:
 Tries to reads until the specified string or \0 is found or the end of stream (see readTillDelimiter:) and returns nil if not enough data has been received yet.
 
(OFString *) - tryReadTillDelimiter:encoding:
 Tries to read until the specified string or \0 is found or the end of stream occurs (see readTillDelimiterWithEncoding:) and returns nil if not enough data has been received yet.
 
(BOOL) - writeBufferEnabled
 Returns a boolen whether writes are buffered.
 
(void) - setWriteBufferEnabled:
 Enables or disables the write buffer.
 
(void) - flushWriteBuffer
 Writes everythig in the write buffer to the stream.
 
(void) - writeBuffer:length:
 Writes from a buffer into the stream.
 
(void) - writeInt8:
 Writes a uint8_t into the stream.
 
(void) - writeBigEndianInt16:
 Writes a uint16_t into the stream, encoded in big endian.
 
(void) - writeBigEndianInt32:
 Writes a uint32_t into the stream, encoded in big endian.
 
(void) - writeBigEndianInt64:
 Writes a uint64_t into the stream, encoded in big endian.
 
(void) - writeBigEndianFloat:
 Writes a float into the stream, encoded in big endian.
 
(void) - writeBigEndianDouble:
 Writes a double into the stream, encoded in big endian.
 
(size_t) - writeBigEndianInt16s:count:
 Writes the specified number of uint16_ts into the stream, encoded in big endian.
 
(size_t) - writeBigEndianInt32s:count:
 Writes the specified number of uint32_ts into the stream, encoded in big endian.
 
(size_t) - writeBigEndianInt64s:count:
 Writes the specified number of uint64_ts into the stream, encoded in big endian.
 
(size_t) - writeBigEndianFloats:count:
 Writes the specified number of floats into the stream, encoded in big endian.
 
(size_t) - writeBigEndianDoubles:count:
 Writes the specified number of doubles into the stream, encoded in big endian.
 
(void) - writeLittleEndianInt16:
 Writes a uint16_t into the stream, encoded in little endian.
 
(void) - writeLittleEndianInt32:
 Writes a uint32_t into the stream, encoded in little endian.
 
(void) - writeLittleEndianInt64:
 Writes a uint64_t into the stream, encoded in little endian.
 
(void) - writeLittleEndianFloat:
 Writes a float into the stream, encoded in little endian.
 
(void) - writeLittleEndianDouble:
 Writes a double into the stream, encoded in little endian.
 
(size_t) - writeLittleEndianInt16s:count:
 Writes the specified number of uint16_ts into the stream, encoded in little endian.
 
(size_t) - writeLittleEndianInt32s:count:
 Writes the specified number of uint32_ts into the stream, encoded in little endian.
 
(size_t) - writeLittleEndianInt64s:count:
 Writes the specified number of uint64_ts into the stream, encoded in little endian.
 
(size_t) - writeLittleEndianFloats:count:
 Writes the specified number of floats into the stream, encoded in little endian.
 
(size_t) - writeLittleEndianDoubles:count:
 Writes the specified number of doubles into the stream, encoded in little endian.
 
(size_t) - writeDataArray:
 Writes from an OFDataArray into the stream.
 
(size_t) - writeString:
 Writes a string into the stream, without the trailing zero.
 
(size_t) - writeLine:
 Writes a string into the stream with a trailing newline.
 
(size_t) - writeFormat:
 Writes a formatted string into the stream.
 
(size_t) - writeFormat:arguments:
 Writes a formatted string into the stream.
 
(size_t) - pendingBytes
 Returns the number of bytes still present in the internal read cache.
 
(BOOL) - isBlocking
 Returns whether the stream is in blocking mode.
 
(void) - setBlocking:
 Enables or disables non-blocking I/O.
 
(int) - fileDescriptorForReading
 Returns the file descriptor for the read end of the stream.
 
(int) - fileDescriptorForWriting
 Returns the file descriptor for the write end of the stream.
 
(void) - close
 Closes the stream.
 
(size_t) - lowlevelReadIntoBuffer:length:
 Performs a lowlevel read.
 
(void) - lowlevelWriteBuffer:length:
 Performs a lowlevel write.
 
(BOOL) - lowlevelIsAtEndOfStream
 Returns whether the lowlevel is at the end of the stream.
 
- Instance Methods inherited from OFObject
(id) - init
 Initializes an already allocated object.
 
(OFString *) - className
 Returns the name of the object's class.
 
(OFString *) - description
 Returns a description for the object.
 
(void *) - allocMemoryWithSize:
 Allocates memory and stores it in the object's memory pool.
 
(void *) - allocMemoryWithSize:count:
 Allocates memory for the specified number of items and stores it in the object's memory pool.
 
(void *) - resizeMemory:size:
 Resizes memory in the object's memory pool to the specified size.
 
(void *) - resizeMemory:size:count:
 Resizes memory in the object's memory pool to the specific number of items of the specified size.
 
(void) - freeMemory:
 Frees allocated memory and removes it from the object's memory pool.
 
(void) - dealloc
 Deallocates the object.
 
(void) - performSelector:afterDelay:
 Performs the specified selector after the specified delay.
 
(void) - performSelector:withObject:afterDelay:
 Performs the specified selector with the specified object after the specified delay.
 
(void) - performSelector:withObject:withObject:afterDelay:
 Performs the specified selector with the specified objects after the specified delay.
 
(void) - performSelector:onThread:waitUntilDone:
 Performs the specified selector on the specified thread.
 
(void) - performSelector:onThread:withObject:waitUntilDone:
 Performs the specified selector on the specified thread with the specified object.
 
(void) - performSelector:onThread:withObject:withObject:waitUntilDone:
 Performs the specified selector on the specified thread with the specified objects.
 
(void) - performSelectorOnMainThread:waitUntilDone:
 Performs the specified selector on the main thread.
 
(void) - performSelectorOnMainThread:withObject:waitUntilDone:
 Performs the specified selector on the main thread with the specified object.
 
(void) - performSelectorOnMainThread:withObject:withObject:waitUntilDone:
 Performs the specified selector on the main thread with the specified objects.
 
(void) - performSelector:onThread:afterDelay:
 Performs the specified selector on the specified thread after the specified delay.
 
(void) - performSelector:onThread:withObject:afterDelay:
 Performs the specified selector on the specified thread with the specified object after the specified delay.
 
(void) - performSelector:onThread:withObject:withObject:afterDelay:
 Performs the specified selector on the specified thread with the specified objects after the specified delay.
 
(OFString *) - stringBySerializing
 Creates a string by serializing the receiver.
 
- Instance Methods inherited from <OFObject>
(BOOL) - isKindOfClass:
 Returns a boolean whether the object of the specified kind.
 
(BOOL) - isMemberOfClass:
 Returns a boolean whether the object is a member of the specified class.
 
(BOOL) - respondsToSelector:
 Returns a boolean whether the object responds to the specified selector.
 
(IMP) - methodForSelector:
 Returns the implementation for the specified selector.
 
(const char *) - typeEncodingForSelector:
 Returns the type encoding for the specified selector.
 
(id) - performSelector:
 Performs the specified selector.
 
(id) - performSelector:withObject:
 Performs the specified selector with the specified object.
 
(id) - performSelector:withObject:withObject:
 Performs the specified selector with the specified objects.
 
(BOOL) - isEqual:
 Checks two objects for equality.
 
(uint32_t) - hash
 Calculates a hash for the object.
 
(id) - retain
 Increases the retain count.
 
(unsigned int) - retainCount
 Returns the retain count.
 
(void) - release
 Decreases the retain count.
 
(id) - autorelease
 Adds the object to the topmost OFAutoreleasePool of the thread's autorelease pool stack.
 
(id) - self
 Returns the receiver.
 
(BOOL) - isProxy
 Returns whether the object is a proxy object.
 
- Instance Methods inherited from <OFCopying>
(id) - copy
 Copies the object.
 

Class Methods

(instancetype) + fileWithPath:mode:
 Creates a new OFFile with the specified path and mode.
 
(instancetype) + fileWithFileDescriptor:
 Creates a new OFFile with the specified file descriptor.
 
(OFString *) + currentDirectoryPath
 Returns the path fo the current working directory.
 
(BOOL) + fileExistsAtPath:
 Checks whether a file exists at the specified path.
 
(BOOL) + directoryExistsAtPath:
 Checks whether a directory exists at the specified path.
 
(void) + createDirectoryAtPath:
 Creates a directory at the specified path.
 
(void) + createDirectoryAtPath:createParents:
 Creates a directory at the specified path.
 
(OFArray *) + filesInDirectoryAtPath:
 Returns an array with the files in the specified directory.
 
(void) + changeToDirectoryAtPath:
 Changes the current working directory.
 
(off_t) + sizeOfFileAtPath:
 Returns the size of the specified file.
 
(OFDate *) + modificationDateOfFileAtPath:
 Returns the date of the last modification of the file.
 
(void) + changeModeOfFileAtPath:mode:
 Changes the mode of a file.
 
(void) + changeOwnerOfFileAtPath:owner:group:
 Changes the owner of a file.
 
(void) + copyFileAtPath:toPath:
 Copies a file.
 
(void) + renameFileAtPath:toPath:
 Renames a file.
 
(void) + deleteFileAtPath:
 Deletes a file.
 
(void) + deleteDirectoryAtPath:
 Deletes an empty directory.
 
(void) + linkFileAtPath:toPath:
 Creates a hard link for a file.
 
(void) + symlinkFileAtPath:toPath:
 Creates a symbolink link for a file.
 

Detailed Description

A class which provides functions to read, write and manipulate files.

Method Documentation

+ (void) changeModeOfFileAtPath: (OFString*)  path
mode: (mode_t)  mode 

Changes the mode of a file.

Only changes read-only flag on Windows.

Parameters
pathThe path to the file of which the mode should be changed as a string
modeThe new mode for the file
+ (void) changeOwnerOfFileAtPath: (OFString*)  path
owner: (OFString*)  owner
group: (OFString*)  group 

Changes the owner of a file.

Not available on Windows.

Parameters
pathThe path to the file of which the owner should be changed as a string
ownerThe new owner for the file
groupThe new group for the file
+ (void) changeToDirectoryAtPath: (OFString*)  path

Changes the current working directory.

Parameters
pathThe new directory to change to
+ (void) copyFileAtPath: (OFString*)  source
toPath: (OFString*)  destination 

Copies a file.

Parameters
sourceThe file to copy
destinationThe destination path
+ (void) createDirectoryAtPath: (OFString*)  path

Creates a directory at the specified path.

Parameters
pathThe path of the directory
+ (void) createDirectoryAtPath: (OFString*)  path
createParents: (BOOL)  createParents 

Creates a directory at the specified path.

Parameters
pathThe path of the directory
createParentsWhether to create the parents of the directory
+ (OFString *) currentDirectoryPath

Returns the path fo the current working directory.

Returns
The path of the current working directory
+ (void) deleteDirectoryAtPath: (OFString*)  path

Deletes an empty directory.

Parameters
pathThe path to the directory which should be deleted as a string
+ (void) deleteFileAtPath: (OFString*)  path

Deletes a file.

Parameters
pathThe path to the file of which should be deleted as a string
+ (BOOL) directoryExistsAtPath: (OFString*)  path

Checks whether a directory exists at the specified path.

Parameters
pathThe path to check
Returns
A boolean whether there is a directory at the specified path
+ (BOOL) fileExistsAtPath: (OFString*)  path

Checks whether a file exists at the specified path.

Parameters
pathThe path to check
Returns
A boolean whether there is a file at the specified path
+ (OFArray *) filesInDirectoryAtPath: (OFString*)  path

Returns an array with the files in the specified directory.

Parameters
pathThe path of the directory
Returns
An array of OFStrings with the files at the specified path
+ (instancetype) fileWithFileDescriptor: (int)  fileDescriptor

Creates a new OFFile with the specified file descriptor.

Parameters
fileDescriptorA file descriptor, returned from for example open(). It is not closed when the OFFile object is deallocated!
Returns
A new autoreleased OFFile
+ (instancetype) fileWithPath: (OFString*)  path
mode: (OFString*)  mode 

Creates a new OFFile with the specified path and mode.

Parameters
pathThe path to the file to open as a string
modeThe mode in which the file should be opened as a string
Returns
A new autoreleased OFFile
- (id) initWithFileDescriptor: (int)  fileDescriptor

Initializes an already allocated OFFile.

Parameters
fileDescriptorA file descriptor, returned from for example open(). It is not closed when the OFFile object is deallocated!
- (id) initWithPath: (OFString*)  path
mode: (OFString*)  mode 

Initializes an already allocated OFFile.

Parameters
pathThe path to the file to open as a string
modeThe mode in which the file should be opened as a string
Returns
An initialized OFFile
+ (void) linkFileAtPath: (OFString*)  source
toPath: (OFString*)  destination 

Creates a hard link for a file.

Not available on Windows.

Parameters
sourceThe path to the file of which should be linked as a string
destinationThe path to where the file should be linked as a string
+ (OFDate *) modificationDateOfFileAtPath: (OFString*)  path

Returns the date of the last modification of the file.

Returns
The date of the last modification of the file
+ (void) renameFileAtPath: (OFString*)  source
toPath: (OFString*)  destination 

Renames a file.

Parameters
sourceThe file to rename
destinationThe new name
+ (off_t) sizeOfFileAtPath: (OFString*)  path

Returns the size of the specified file.

Returns
The size of the specified file
+ (void) symlinkFileAtPath: (OFString*)  source
toPath: (OFString*)  destination 

Creates a symbolink link for a file.

Not available on Windows.

Parameters
sourceThe path to the file of which should be symlinked as a string
destinationThe path to where the file should be symlinked as a string

The documentation for this class was generated from the following files: