https://kotlinlang.org logo
Join SlackCommunities
Powered by
# io
  • z

    Zhang Zihan

    05/12/2024, 5:19 PM
    Hello! Can
    RawSource.readAtMostTo(sink, byteCount)
    read at most 8192 bytes at a time? How to read more at once?
    f
    • 2
    • 4
  • f

    Florian Levis

    05/17/2024, 9:12 PM
    👋 Is there plans to add UByte* support to kotlinx-io? i.e. having this signature function for example:
    Copy code
    public fun Source.readAtMostTo(sink: UByteArray, startIndex: Int = 0, endIndex: Int = sink.size): Int
    I know unsigned types are still flagged as experimental Right now I'm using the function
    .toUByteArray()
    on the sink after using it; so it's not a blocking issue. Thanks. Regards.
    youtrack 1
    ✅ 1
    f
    • 2
    • 2
  • f

    Florian Levis

    05/30/2024, 4:01 PM
    👋 I'm looking for a way to know the source's length, without consuming it until the end. I would like to skip but with some control before
    ✅ 1
    f
    • 2
    • 4
  • e

    Edoardo Luppi

    06/10/2024, 10:06 AM
    @Filipp Zhinkin hey! Now that you've switched to 2.0, are you considering switching from Yarn to npm? If official libraries start switching to npm support, we might find and fix bugs.
    f
    a
    • 3
    • 13
  • e

    Edoardo Luppi

    06/10/2024, 3:42 PM
    @Filipp Zhinkin I was looking at the benchmarks you published. Thanks for that! I wasn't sure why when working on antlr-kotlin I was seeing much worse results with object namespacing, so I cloned and compiled the benchmarks. Looks like for some reason, there is no lazy init of
    SomeApi
    ! See the
    SomeApi_instance = new SomeApi();
    bit
    Copy code
    function FunctionCallBenchmark() {
      this.re_1 = 0;
    }
    protoOf(FunctionCallBenchmark).se = function (bh) {
      // Inline function 'kotlinx.benchmark.Blackhole.consume' call
      var i = freeFunction(0);
      bh.pe(i);
    };
    protoOf(FunctionCallBenchmark).te = function (bh) {
      // Inline function 'kotlinx.benchmark.Blackhole.consume' call
      var i = SomeApi_instance.callOnObject(0);
      bh.pe(i);
    };
    function SomeApi() {
    }
    protoOf(SomeApi).callOnObject = function (x) {
      return imul(x, 2);
    };
    var SomeApi_instance;
    function SomeApi_getInstance() {
      return SomeApi_instance;
    }
    function freeFunction(x) {
      return imul(x, 2);
    }
    //region block: init
    SomeApi_instance = new SomeApi();
    //endregion
    //region block: exports
    function $jsExportAll$(_) {
      var $org = _.org || (_.org = {});
      var $org$example = $org.example || ($org.example = {});
      defineProp($org$example, 'SomeApi', SomeApi_getInstance);
      $org$example.freeFunction = freeFunction;
    }
    $jsExportAll$(_);
    _.$jsExportAll$ = $jsExportAll$;
    _.$_$ = _.$_$ || {};
    _.$_$.a = FunctionCallBenchmark;
    //endregion
    return _;
    f
    • 2
    • 11
  • c

    Colin White

    07/18/2024, 6:37 PM
    Hi I was wondering if there’s any prior art for copying a
    kotlinx.io.Source
    into an
    okio.Sink
    ? I’m currently creating an intermediate
    ByteArray
    to write the bytes to then writing those bytes to the
    okio.Sink
    , but I’m wondering if there’s a better way
    f
    • 2
    • 2
  • f

    Francis Mariano

    08/05/2024, 8:31 PM
    Hello everyone. Dummy question here, I never used kotlinx-io before. I want write simple text to a file, and append more text later. Can use a sink for that??
    m
    • 2
    • 2
  • c

    Colton Idle

    08/07/2024, 4:48 PM
    In kotlinx.io Buffer().get(Long) - returns byte at position (Long) Not sure if I'm missing something, but is there any way to read short at desired position in Kotlinx.io Buffer?
    e
    • 2
    • 6
  • f

    Filipp Zhinkin

    08/12/2024, 9:56 PM
    set the channel description: Discussions covering various topics related to I/O in Kotlin.
  • f

    Filipp Zhinkin

    08/12/2024, 9:56 PM
    set the channel description: Discussions covering various topics related to I/O in Kotlin
  • f

    Filipp Zhinkin

    08/12/2024, 9:56 PM
    set the channel topic: Discussions covering various topics related to I/O in Kotlin
  • g

    Gary Peck

    08/17/2024, 9:35 AM
    Hi, is it possible to get a `Sink`/`Source` that corresponds to stdout/stdin using kotlinx.io on Native and WasmWasi?
    f
    • 2
    • 2
  • j

    Javier

    10/09/2024, 9:24 PM
    With
    kotlinx-io
    is there any easy way to read a file from the
    resources
    directory?
    f
    • 2
    • 1
  • a

    alexandre mommers

    10/11/2024, 1:20 PM
    does kotlinx-io allow to manipulate byte buffer outside JVM heap ? for example to send it to a C library ?
    f
    • 2
    • 2
  • m

    Morten Minke

    11/25/2024, 7:39 PM
    I have an issue using kotlinx.io in a kotlin mpp. The situation is that I use FileKit (https://github.com/vinceglb/FileKit) to select files on the different platforms (android, ios, jvm, etc.). FileKit returns a PlatformFile which can return a PlatformInputStream. This stream has a
    readInto
    method which is a suspend method (which makes sense with io operations). I want convert this FileKit specific PlatformInputStream into a generic kotlinx.io (Raw)Source to further use in my application. However, the kotlinx.io RawSource has a method, override fun
    readAtMostTo
    , which I need to implement for this, but this method is not a suspend function. Because this is a MPP and both FileKit and kotlinx.io are also MPP I think I should be able to make this work in common code, but I fail because the readInto method is not a suspend function but I need a coroutine context to call the readAtMostTo and wait for the result to return. In jvm I would be able to use runBlocking to call and wait for the result, but this is not possible in MPP common code. I really thought about different solutions but I cannot find a good solution for this. Does anybody have an idea? For simplicity here is some pseudo code showing what I try to achieve:
    Copy code
    class PlatformInputStreamSource(
        private val platformInputStream: PlatformInputStream
    ) : RawSource {
        override fun readAtMostTo(sink: Buffer, byteCount: Long): Long {
            ...
            
            << Here i need to start a coroutine context and wait for the numberOfBytesCopied
            val numberOfBytesCopied = platformInputStream.readInto(buffer, byteCount, bufferSize))
            
            ...
            
            << This non suspend function needs to return the number of bytes copied and therefor has to wait for the result from the readInto function.
            return numberOfBytesCopied.toLong()
        }
    }
    f
    • 2
    • 2
  • s

    suresh

    11/25/2024, 9:49 PM
    Hi, apart from file I/O, what are the future plans for kotlinx-io APIs? Can we expect some kind of Process (like ProcessHandle) or Signal Handler API to be added to kotlinx-io that will work on all native platforms?
    f
    • 2
    • 3
  • h

    hfhbd

    11/26/2024, 8:59 PM
    Is this expected that calling
    myRawSource.buffered().buffered().buffered()
    creates a new RealSource each time? Shouldn't be there an extension on
    Source.buffered() = this
    ?
    f
    • 2
    • 4
  • h

    hfhbd

    12/04/2024, 12:49 PM
    On JVM only, I need to create an OutputStream to write 10 MB (data comes from memory, json encoding) over the wire. Should I use ByteArrayOutputStream or kotlinx Buffer and asOutputSource? Are there any performance differences?
    👀 1
    f
    k
    • 3
    • 7
  • c

    Chris Lee

    12/05/2024, 7:15 PM
    Haven’t been able to find a good example of using kotlinx.io (or okio) to parse data. As a trivial/contrived example (real world scenarious have more layers/complexity), if you have a stream of records that are line-delimited: a) you need to demarcate a record - find the end of line; b) you need to parse within the line, where various pieces may or may not be required, may be further transformed, etc Yes, you could use readLine() - but that incurs copies into Strings that need to be further parsed. How to properly do the framing / parsing?
    f
    • 2
    • 2
  • e

    edenman

    12/06/2024, 7:02 PM
    I have a kotlinx io Source. I would like to read chunks of size N and only get a smaller chunk if it’s the end of the file. readAtMostTo looks like what I want, but it’s not guaranteed to read the full chunk size
    f
    • 2
    • 7
  • m

    Mark

    12/09/2024, 5:37 AM
    Looking to migrate (with KMP in mind) from using java.io.* in my Android app to using either kotlinx.io or okio. I noticed kotlinx.io doesn’t support much in the way of system file operations (like delete). However, with ktor recently switching from okio to kotlinx.io should I consider okio as a no-go and instead place my bets on kotlinx.io with anticipation of upcoming expanded functionality. I’m not in any huge rush.
    m
    • 2
    • 6
  • t

    Tóth István Zoltán

    12/26/2024, 6:10 AM
    What would be the right way to copy a whole file with kotlinx.io? I wrote this but I'm really not sure it's OK. What does this do with large files?
    Copy code
    fun Path.copy(target: Path, override: Boolean = false) {
        check(target.exists() && ! override) { "file $target already exists" }
        SystemFileSystem.sink(target, append = false).buffered().use { sink ->
            SystemFileSystem.source(this).buffered().use { source ->
                source.transferTo(sink)
            }
        }
    }
    m
    • 2
    • 1
  • r

    Rob Elliot

    03/14/2025, 10:13 AM
    First time using kotlinx.io today and I was a bit thrown that
    kotlinx.io.asSource
    returns a
    RawSource
    , which is not a
    Source
    . Have you considered renaming it to
    kotlinx.io.asRawSource
    , and making
    kotlinx.io.asSource
    syntactic sugar for
    .asRawSource().buffered()
    ?
    f
    • 2
    • 4
  • t

    Tóth István Zoltán

    03/20/2025, 5:55 AM
    When writing files I sometimes like to write into a temporary file first and then rename it to ensure that the file content is always valid. However, as I understand
    atomicMove
    in
    <http://kotlinx.io|kotlinx.io>
    does not support overwriting existing files. Any advices how to achieve this? The problem with
    delete
    +
    atomicMove
    is that there exists a moment where the original file is deleted but the move did not happen yet.
    f
    • 2
    • 2
  • e

    edenman

    04/03/2025, 3:51 PM
    anybody know if there's updates on the Async proposal? trying to implement OPFS storage for web but everything is async and
    Source
    is all sync
    f
    • 2
    • 4
  • r

    RTAkland

    04/05/2025, 10:57 AM
    How do I append a line into a file (kotlinx-io Path)
    f
    • 2
    • 1
  • h

    hfhbd

    04/09/2025, 10:25 AM
    What's the best way to read a local file with random access? Use-case, I have a parquet file that contains the metadata at the end of the file... So I need to read the last 8 bytes to get the start offset of the metadata footer, and then read the file starting from that offset to parse the metadata. I currently have a RawSource, so to "start" reading at a specific offset, I want to use
    rawSource.readAtMostTo()
    , but this api requires a
    Buffer
    , not a
    RawSink
    that can be ignored by an
    discardingSink
    . (I can use
    discardingSink().buffered().buffer
    though, but it is an internal api.)
    f
    k
    • 3
    • 6
  • r

    RTAkland

    04/18/2025, 7:00 AM
    Hi, how to I get a file modification time or timestamp with kotlin native on linux
    f
    • 2
    • 5
  • k

    kevin.cianfarini

    04/25/2025, 8:04 PM
    Why does ByteString need an unused
    dummy: Any?
    parameter which is always null? https://github.com/Kotlin/kotlinx-io/blob/master/bytestring/common/src/ByteString.kt#L81
    👀 3
    e
    • 2
    • 3
  • h

    hfhbd

    05/08/2025, 6:41 AM
    And do you have any plans to support "stream" converters like Base64, or compression like gzip? And what about in memory zip streams (and zip file systems at all)? I currently use the Java api but would like to migrate my code to Kotlin Multiplatform.
    👌 1