nsfilehandle

How to save images and recorded files in temp directory?

不羁岁月 提交于 2020-01-11 05:12:27
问题 I want to store pictures taken from camera and video recordings from my application in a separate folder in temporary directories for a while. And as the task is being completed, they shall be going to save into the database. How do I save pictures taken from camera & video recording files in a separate folder in temp directories? 回答1: You are looking for this to get tot he caches folder to store temporary files: NSString* path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,

How can I catch EPIPE in my NSFIleHandle handling?

眉间皱痕 提交于 2020-01-05 07:44:12
问题 I'm having a problem with EPIPE in my iOS app, and it's not being caught in the @try/@catch/@finally block. How can I catch this signal (SIGPIPE, likely)... I've built a "web proxy" into my app that will handle certain kinds of URLs - in this error case, it seems that the remote end (also in my app, but hiding in the iOS libraries) closes its end of the socket. I don't get a notification (should I? Is there something I should register for with the NSFileHandle that might help here?). I've

How can I tell when a FileHandle has nothing left to be read?

此生再无相见时 提交于 2020-01-04 04:13:06
问题 I'm trying to use a Pipe's fileHandleForReading's readabilityHandler to read both the standardOutput and standardError of a Process. However, the moment the terminationHandler is called is actually before the moment my readabilityHandler is called for the first time. I'm not sure why the process does this, but it means I'm not getting all the data, because I assume process termination means all output has been flushed to the pipe. Since this isn't the case, is there a way for me to tell when

Memory issue while converting big video file path to NSData. How to use InputStream/FileHandle to fix this issue?

佐手、 提交于 2019-12-25 01:34:11
问题 I have a large sized video saved in my documents directory. I want to retrieve this video and remove it's first 5 bytes. For large video files of above 300 MB using [NSData(contentsOf: videoURL)] causing Memory issue error. I have gone through Swift: Loading a large video file (over 700MB) into memory and found that we need to use [InputStream] and [OutputStream] or [NSFileHandle]for large files. How to use it? Sample code is given below: let nsDocumentDirectory = FileManager

How to insert data to text file with using NSFileHandle

点点圈 提交于 2019-12-11 16:45:47
问题 My code replaces text instead of inserting it starting from 5 symbol: NSFileHandle *file = [NSFileHandle fileHandleForUpdatingAtPath: filePath]; [file seekToFileOffset: 5]; [file writeData: [value dataUsingEncoding:NSUTF8StringEncoding]]; Is there any way to insert data to text file? 回答1: That's because your code set the index position to 5 and start writing from there, thus replacing everything from 5 onwards. I would copy the content of the file to a variable and modify it from there as a

Not able to edit first byte of file using NSFileHandle

依然范特西╮ 提交于 2019-12-11 11:09:46
问题 In my app, I am using NSFileHandle to edit some file but it is not editing. Below is the code: with comments & logs output //Initialize file manager NSFileManager *filemgr; filemgr = [NSFileManager defaultManager]; //Initialize file handle NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:filePath]; //Check if file is writable if ([filemgr isWritableFileAtPath:filePath] == YES) NSLog (@"File is writable"); else NSLog (@"File is read only"); //Read 1st byte of file NSData

Can someone help me spot a leak in this NSPipe/NSFileHandle code?

我的未来我决定 提交于 2019-12-11 10:59:50
问题 So I'm having this issue where once this NSFileHandle/NSPipe gets triggered... my CPU use and memory start going crazy. Problem is I'm finding it hard to find this leak. Any advice or help is appreciated. Cheers. .h NSTask *task; NSPipe *pipe; NSFileHandle *fileHandle; @property (weak) IBOutlet NSTextField *commandInputTextField; @property (unsafe_unretained) IBOutlet NSTextView *nsTastOutput; @property (weak) IBOutlet NSButton *useOutputSwitch; .m - (id)init { [[NSNotificationCenter

NSTask only returning standardError in release build

你说的曾经没有我的故事 提交于 2019-12-11 10:34:43
问题 First of all, when debugging and running in Xcode everything works as expected. But when I try to "share" my app, i.e. make a release build, my NSTask won't output any standardOutput while standardErrors ARE put out. How is that possible? My code - (id)initWithWindow:(NSWindow *)window { self = [super initWithWindow:window]; if (self) { // Initialization code here. } [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(readPipe:) name

I'm trying to find a file size. But my length is equl to zero

余生颓废 提交于 2019-12-11 05:46:36
问题 I'm trying to find a file size. NSFileHandle *output = [NSFileHandle fileHandleForWritingAtPath:self.finalPath]; //seek to begin of the file [output seekToFileOffset:0]; NSData *mydata = [output availableData]; NSLog(@"length: %d", [mydata length]); But my length is equl to zero. Why? 回答1: availableData is for reading files. If you just want to find out the size of a file, you don't actually have to open it. Just use NSFileManager like this: NSDictionary *attributes = [[NSFileManager

Overwrite Data using NSFileHandle

余生长醉 提交于 2019-12-10 01:28:55
问题 Using an NSFileHandle, it is pretty easy to remove n number of characters from the end of the file using truncateFileAtOffset. -(void)removeCharacters:(int)numberOfCharacters fromEndOfFile:(NSFileHandle*)fileHandle { unsigned long long fileLength = [fileHandle seekToEndOfFile]; [fileHandle truncateFileAtOffset:fileLength - numberOfCharacters]; } However removing characters from the front of the file doesn't seem possible without having to copy all of the remaining data into memory,