You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In PlatformFile apple implementation, I've noticed that only the readBytes method is using a security scope to access the data, through nsUrl.startAccessingSecurityScopedResource() and nsUrl.stopAccessingSecurityScopedResource().
It seems to cause issues with our app on real apple devices, as we're not able to retrieve the size (getSize()) and the input stream (getStream()) has no bytes available.
On emulators, it's working fine.
Are we doing something wrong ?
The text was updated successfully, but these errors were encountered:
Here is an example in sample-core of how we use PlatformInputStream:
bytes =if (file.supportsStreams()) {
val size = file.getSize()
if (size !=null&& size >0L) {
val buffer =ByteArray(size.toInt())
val tmpBuffer =ByteArray(1000)
var totalBytesRead =0
file.getStream().use {
while (it.hasBytesAvailable()) {
val numRead = it.readInto(tmpBuffer, 1000)
tmpBuffer.copyInto(
buffer,
destinationOffset = totalBytesRead,
endIndex = numRead,
)
totalBytesRead += numRead
}
}
buffer
} else {
file.readBytes()
}
} else {
file.readBytes()
}
I tried to launch this code on my real iPhone this morning, and it seems to work in that case.
That said, we are working on a new version of FileKit bringing a lot of changes. Typically:
PlatformInputStream will be deprecated / removed?
PlatformFile will integrate kotlinx-io operations on Android, Apple targets and JVM
It means that it will be possible to use kotlinx-io Sink and Source easily from a PlatformFile. This way, it will be possible to read and write files like you want. For example, we will use Source to read data from a stream. Also, operations will become much stable since they are maintained by the kotlinx-io library.
Soon, I'm going to publish this new version (0.10) of FileKit. If you are interested in trying this new version now, it's possible!
You can follow the steps in this comment: #143 (comment)
If you have any questions or feedback, don't hesitate!
In
PlatformFile
apple implementation, I've noticed that only thereadBytes
method is using a security scope to access the data, throughnsUrl.startAccessingSecurityScopedResource()
andnsUrl.stopAccessingSecurityScopedResource()
.It seems to cause issues with our app on real apple devices, as we're not able to retrieve the size (
getSize()
) and the input stream (getStream()
) has no bytes available.On emulators, it's working fine.
Are we doing something wrong ?
The text was updated successfully, but these errors were encountered: