Questions tagged [nsfilehandle]

The NSFileHandle class is an object-oriented wrapper for a file descriptor. You use file handle objects to access data associated with files, sockets, pipes, and devices. For files, you can read, write, and seek within the file. For sockets, pipes, and devices, you can use a file handle object to monitor the device and process data asynchronously.

139 questions
5
votes
2 answers

How to read all remaining output of readInBackgroundAndNotify after NSTask has ended?

I'm invoking various command line tools via NSTask. The tools may run for several seconds, and output text constantly to stdout. Eventually, the tool will terminate on its own. My app reads its output asynchronously with…
Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
4
votes
1 answer

Not able to read IHDR chunk of a PNG file

I have read PNG file specification and learnt that after the first 8 bytes of PNG signature, we have the IHDR chunk. This image states that we have IHDR with length of 13(0x0000000D) bytes. I have written a code in swift to read the same png file…
Rohan Bhale
  • 1,323
  • 1
  • 11
  • 29
4
votes
1 answer

Using NSFileHandle on Swift 3

How could I write this method in Swift 3? extension NSFileHandle { func readUInt32() -> UInt32? { let data = self.readDataOfLength(4) guard data.length == 4 else { return nil } return…
Lucas Farah
  • 1,022
  • 10
  • 24
4
votes
1 answer

Writing to a new line of a file in Objective-C

For some strange reason, the \n and \r escape sequences do not seem to be working in my code. I want to write each NSString on a new line of the file, but it just appends it the last string on one line. Here's the code: for (Entry *entry in…
Kulpreet
  • 160
  • 2
  • 14
4
votes
1 answer

How to get FILE * from NSFileHandle *?

An old parser relies on a FILE * to work. However, the Dropbox Sync API for iOS returns a NSFileHandle * instead of a FILE * as a file handle. So I try to use fileDescriptor of a NSFileHandle: - (NSFileHandle )readHandle:(DBError *)error Returns…
ohho
  • 50,879
  • 75
  • 256
  • 383
4
votes
1 answer

NSString containing hex convert to ascii equivalent

I have an NSString that has hex information such as <00000020 66747970 4d344120 00000000 4d344120 6d703432 69736f6d 00000000 00031203 which came from NSData. What I need to do is convert that NSString of Hex data to Ascii which would be: [0][0][0]…
broccolifarmer
  • 465
  • 7
  • 15
3
votes
1 answer

NSFileHandle & Writing Asynch to a file in iOS

I have a situation that I receive a byte data through Web Services request and want to write it to a file on my iOS device. I used to append all data (till end of data) in a memory variable and at the end writing the data using NSStream to a file in…
Cam
  • 275
  • 6
  • 24
3
votes
2 answers

How do I check for NSFileHandle has data available?

I'm working with NSTask, configured with 3 NSPipe, and want to read from standardOutput and standardError. I do it inside while - 1st for stdout, next for stderr. I can't use readInBackgroundAndNotify and waitForDataInBackgroundAndNotify, since my…
UncleMiF
  • 1,051
  • 2
  • 11
  • 20
3
votes
2 answers

How to PREPEND text to a file in Swift or Objective C?

Please note that I'm not asking how to append texts at the end of the file. I'm asking how to prepend texts to the beginning of file. let handle = try FileHandle(forWritingTo: someFile) //handle.seekToEndOfFile() // This is for…
7ball
  • 2,183
  • 4
  • 26
  • 61
3
votes
1 answer

What exactly is a communication channel?

When I look at the NSFileHandle API docs, I see there are a lot of networking methods talking about sockets and stuff like that... At the top, they say: NSFileHandle objects provide an object-oriented wrapper for accessing open files or…
Proud Member
  • 40,078
  • 47
  • 146
  • 231
3
votes
1 answer

iOS: NSFileHandle vs NSOutputStream for large file download

On iOS, our application is downloading a zip file that's approximately 400MB. We're getting intermittent crashing while the file is downloading. Current I'm using [NSFileHandle writeData:] to write the data as it comes in, and is not being stored in…
gngrwzrd
  • 5,902
  • 4
  • 43
  • 56
3
votes
1 answer

Exception `-[NSConcreteFileHandle readDataOfLength:]: Bad file descriptor` when running a NSUserUnixTask

I'm using NSUserUnixTask to run an unsandboxed NSTask on my sandboxed app. However, my code hangs on calls to [NSFileHandle readDataToEndOfFile]. If I remove those calls it works perfectly. If I replace [NSFileHandle readDataToEndOfFile] with…
Alex
  • 5,009
  • 3
  • 39
  • 73
3
votes
1 answer

Writing data to the file on device and reading it back from the device (iPhone)

What is the easiest way to programatically create file.txt on your device, then in your application write down some data and then send this data to your Computer? I guess that the last part could be done programatically same as using some program on…
user1246957
  • 103
  • 2
  • 8
2
votes
2 answers

Async execution of shell command not working properly

So, this is my code : - (void)runCmd:(NSString *)cmd withArgs:(NSArray *)args { NSLog(@"\nRunning ::\n\tCmd : %@\n\tArgs : %@",cmd, args); [theSpinner start]; if (task) { [task interrupt]; } else { task =…
Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
2
votes
3 answers

NSTask only returning standardError in release build

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 -…
ThomasM
  • 2,647
  • 3
  • 25
  • 30
1
2
3
9 10