Skip to content

Make Source to/from InputStream and Sink to/from OutputStream consistent #451

@vdshb

Description

@vdshb

On JVM target there is a strange (at the first glance) decision to make
Source.asInputStream(): InputStream with InputStream.asSource(): RawSource
and
Sink.asOutputStream(): OutputStream with OutputStream.asSink(): RawSink

Hence such simple and intuitive pipelines:

import kotlinx.io.Buffer
import kotlinx.io.Source
import kotlinx.io.asInputStream
import kotlinx.io.asOutputStream
import kotlinx.io.asSink
import kotlinx.io.asSource

fun main() {
  Buffer().asInputStream().asSource().asInputStream()
  Buffer().asOutputStream().asSink().asOutputStream()
}

are impossible (broken at the last chain link) with current API.

(Of cause I don't need to make such chains, but I care about API consistency and about ability to convert in/from InputStream easily)

I think it might be good to consider:

option 1)
refactor Source.asInputStream() -> RawSource.asInputStream()
refactor Sink.asOutputStream() -> RawSink.asOutputStream()

oprion 2)
rename InputStream.asSource(): RawSource -> InputStream.asRawSource(): RawSource
rename OutputStream.asSink(): RawSink -> OutputStream.asRawSink(): RawSink
add OutputStream.asSink(): Sink
add InputStream.asSource(): Source

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions