Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-06-07 Thread Brent Royal-Gordon via swift-users
>> It’s almost unique in that regard; in general Cocoa APIs are only supposed >> to throw exceptions for programmer errors like assertion failures. > > Almost unique is right. The only other offender I can think of is > Distributed Objects, which is even less fun because any method call > (inc

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-06-06 Thread Quinn "The Eskimo!" via swift-users
On 5 Jun 2016, at 11:36, Jens Alfke wrote: > It’s almost unique in that regard; in general Cocoa APIs are only supposed to > throw exceptions for programmer errors like assertion failures. Almost unique is right. The only other offender I can think of is Distributed Objects, which is even le

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-06-05 Thread Matthias Zenger via swift-users
Yes, error reporting is missing (errors are treated like EOF), but your proposal breaks encapsulation. By not making `NSInputStream` a hidden implementation detail, you make it possible for clients to interfere with the caching logic (e.g. by directly invoking `read`, or prematurely closing the ste

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-06-05 Thread Brent Royal-Gordon via swift-users
> Looks good, but you'll want some error handling. There's no clean way to > integrate it with Generator because the protocol doesn't allow the > implementation to throw, unfortunately. (I've run into the same problem > building a Generator around a database query.) I think the best solution is

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-06-05 Thread Jens Alfke via swift-users
Looks good, but you'll want some error handling. There's no clean way to integrate it with Generator because the protocol doesn't allow the implementation to throw, unfortunately. (I've run into the same problem building a Generator around a database query.) I think the best solution is to add

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-06-05 Thread Matthias Zenger via swift-users
Quinn, Jens, thanks for pointing me at the NSStream classes. For some reason, I discarded NSStream quickly after seeing the first paragraph of Apple's documentation on output streams

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-06-05 Thread Jens Alfke via swift-users
> On Jun 4, 2016, at 6:25 PM, Matthias Zenger via swift-users > wrote: > > I wanted to use NSFileHandle (for a use case that requires streaming) and > realized that this is an API that cannot really be used in Swift because it's > based on Objective-C exceptions. You’re right, NSFileHandle i

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-06-05 Thread Quinn "The Eskimo!" via swift-users
On 5 Jun 2016, at 02:25, Matthias Zenger wrote: > I still don't understand if it's currently actually *possible* to use non > C-based solutions in Swift which use streaming. I wanted to use NSFileHandle > (for a use case that requires streaming) and realized that this is an API > that cannot

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-06-04 Thread Matthias Zenger via swift-users
Quinn, thanks for the example. I agree that Foundation makes it easier by loading the data fully into memory. I still don't understand if it's currently actually *possible* to use non C-based solutions in Swift which use streaming. I wanted to use NSFileHandle (for a use case that requires streamin

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-23 Thread Quinn "The Eskimo!" via swift-users
On 18 May 2016, at 23:02, John Myers via swift-users wrote: > I've been having trouble figuring out how to read and write data to a > textfile, and not finding much out there for Swift on Linux. Sorry about being complicit in the one-shot vs streaming I/O diversion. It’s true that Swift’s s

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-20 Thread Jens Alfke via swift-users
> On May 20, 2016, at 9:44 AM, Jan Neumüller via swift-users > wrote: > > What advantage? Streaming IO is a pain in the . I never got what people > like at this stuff Well for one, it abstracts away the source of the data. It could be a file, a TCP socket, an HTTP body, the output of ano

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-20 Thread Jan Neumüller via swift-users
> +1. There are many reasons to prefer streaming implementations. It is also > possible to write high-level APIs with relatively simple interfaces that use > streaming behind the scenes. The fact that this is not always done is not a > good argument against providing robust streaming APIs. I

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-20 Thread Matthew Johnson via swift-users
> On May 20, 2016, at 10:47 AM, Jens Alfke via swift-users > wrote: > > >> On May 20, 2016, at 1:16 AM, Quinn The Eskimo! via swift-users >> mailto:swift-users@swift.org>> wrote: >> >> One of the nice things about the file system is that it has reasonable >> performance and error characteri

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-20 Thread Jens Alfke via swift-users
> On May 20, 2016, at 1:16 AM, Quinn The Eskimo! via swift-users > wrote: > > One of the nice things about the file system is that it has reasonable > performance and error characteristics such that you /can/ deal with it > synchronously. Revel in that fact! That’s only really true at small

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-20 Thread Gerard Iglesias via swift-users
Hello Interesting question From my point of view, I want to parse a huge file without loading it in memory... Maybe something worth the reading https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/TechniquesforReadingandWritingCustomFile

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-20 Thread Maury Markowitz via swift-users
> On May 20, 2016, at 4:16 AM, Quinn The Eskimo! via swift-users > wrote: > I disagree. One-shot file system APIs make sense for a lot of reasons: I do most of my programming in .Net, where streams are the primary IO system. Even simple tasks often require multiple objects and loops copying da

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-20 Thread Quinn "The Eskimo!" via swift-users
On 19 May 2016, at 17:38, Jens Alfke wrote: > I believe Mac/iOS developers usually transfer the entire file because that’s > the particular hammer that Foundation provides. I disagree. One-shot file system APIs make sense for a lot of reasons: * It’s generally easier to use. Consider NSXMLD

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-19 Thread Jens Alfke via swift-users
> On May 19, 2016, at 12:58 AM, Quinn The Eskimo! via swift-users > wrote: > > The reason I ask is that most of the time when I mess around with files I > transfer the entire file to and from memory, which is something that the > Foundation APIs excel at. I believe Mac/iOS developers usually

Re: [swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-19 Thread Quinn "The Eskimo!" via swift-users
On 18 May 2016, at 23:02, John Myers via swift-users wrote: > I've been having trouble figuring out how to read and write data to a > textfile … Your examples show you transferring the data line-by-line. Is that the end goal? Or just fallout from what you happened to get working? The reas

[swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-18 Thread John Myers via swift-users
I've been having trouble figuring out how to read and write data to a textfile, and not finding much out there for Swift on Linux. I found code for reading data from a file on StackOverflow that works for me, but cludged together my own code for writing to a file. I'm not sure exactly what I'm do