BufReader for Swift

A work in progress: feat: initial work by sstadick · Pull Request #1 · sstadick/SwiftIO · GitHub

If anyone more experienced with Swift feels like commenting on this PR I'd be grateful! This is an attempt to create BufReader and BufWriter similar to Rust, but for swift, mostly for CLI type programs / data crunching on files that are too large to hold in memory. This is a first pass at the BufReader

The intent would be for this to be cross platform and not just for Mac, which I think means I'd need to not use FileHandle from Foundations?

1 Like

If this is primarily for file systems, have you had a look at NIOFilesystem in SwiftNIO https://github.com/apple/swift-nio/pull/2615 which just landed. It's not in a release yet though. If you want a cross platform solution not dependent on Foundation this might be worth looking into.


Yes, and if you already depend on SwiftNIO, its ByteBuffer type can do a lot of things you'd expect from BufReader and BufWriter.


I'll have to go do some reading! I haven't really gotten into async Swift yet.

On reading more, Foundation is supported on linux it looks like, so FileHandle should be cross-platform enough for me. I do think there's value in having sync versions of BufReader and BufWriter (at least for myself wring CLI tools). Reading the NIO code is very instructive on writing better Swift though!

A thing worth considering is that swift-corelibs-foundation is no longer actively maintained, while SwiftNIO is. OTOH swift-corelibs-foundation supports Windows (to some degree), unlike SwiftNIO.

Ufff, that sucks.

So there is no currently maintained standard library on linux for non-async?

This could be the one, it matches low-level system APIs as closely as possible while providing safe Swift wrappers around those:


Oh that's perfect. Hope restored.