I'm fairly new to Swift and very new to NIO.
I'm adding Swift code to a large project that needs to up/down load a lot of data (GBs) to AWS. To that end, I've imported the GitHub project Soto, which relies heavily on NIO.
Most methods that send/receive data do so through ByteBuffer structs. My application already has the data to upload in Foundation Data objects. I'm having trouble figuring out the best way to get these Data objects into NIO.
In the documentation for NIO's ByteBuffer (2.26.0) it states
Supported types: A variety of types can be read/written from/to a ByteBuffer. ... Out of the box, ByteBuffer supports for example the following types (non-exhaustive list):
- String/StaticString
- Swift’s various (unsigned) integer types
- Foundation‘s Data
- [UInt8] and generally any Collection of UInt8
However, the latest swift-nil package has no ByteBuffer support for Foundation Data objects. Instead, it supports DispatchData objects, which in turn seem to have no interoperability with Data objects.
What I want to avoid is making a copy of every block of data (100's of MB at a time), just to convert between Data and DispatchData types.
So...
Right now my thinking is one of
I'm completely lost, and there's a simple solution I haven't found
The solution is to create a subclass of
DispatchDatabacked by aDataobjectInitialize the
ByteBufferstructure using aDispatchDatacreated using the no-copy initializer pointing to the raw byte array in theDataobject, along with a custom deallocator that simply retains theDataobject until theByteBufferandDispatchDataobjects are destroyed.
I would appreciate any thoughts, experience, or suggestions (particularly if it's option #1).