> Le 9 mars 2021 à 09:07, Allan Odgaard via Cocoa-dev 
> <cocoa-dev@lists.apple.com> a écrit :
> 
> We currently have two different systems that can’t easily be bridged, 
> effectively doing the same thing, but supporting different sources:
> 
> NSStream can work with files, data, and network streams (created by 
> NSURLSession and other high-level API).
> 
> NSFileHandle can work with files, pipes, stdin/out/error, file descriptors, 
> and due to the latter, sockets created with lower level API.
> 
> When designing new API, I am torn between which of these two interfaces I 
> should support. Semantically I like NSInputStream if I have an API that 
> consume data, but this choice means my API cannot be used with pipes, 
> something which is quite useful for interprocess communication / NSTask, nor 
> with stdin, something I frequently consume in CLI tools.
> 
> OTOH streams do support “bounding” so it’s easy to create self-contained 
> filters and insert them into a stream.
> 
> Any thoughts on this? Have you selected one of them in your API only to 
> regret it later?
> 
> I think introducing a class method to NSStream that creates a read/write 
> stream from an NSFileHandle would go along way. Why has Apple never had this 
> need themselves (to make it part of the public API)?
> 
> It’s probably worth also mentioning blocks, today many things that are 
> “streams” are instead handled via callbacks, which makes the API easier to 
> use for majority of cases, but it is less formalized, so harder to make 
> reusable components to process such (stream) data.

IIRC, NSFileHandle sometimes throws exception, which make it unusable in modern 
software (Swift can’t catch obj-c exception, and they never where really 
considered safe anyway).

If I had to write a new software that need read/write functions today, I would 
go for a modern async API, like dispatch_io.  

Especially as Swift async API are in a good way to be released this year and 
will make writing callback based API far easier.




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to