override fun mywrite()

in plot-api/src/commonMain/kotlin/org/jetbrains/letsPlot/util/pngj/pixels/CompressorStreamLz4.kt [54:77]


    override fun mywrite(data: ByteArray, off: Int, len: Int) {
        @Suppress("NAME_SHADOWING")
        var off = off
        @Suppress("NAME_SHADOWING")
        var len = len
        if (len == 0) return
        if (isDone || isClosed) throw PngjOutputException("write beyond end of stream")
        bytesIn += len.toLong()
        while (len > 0) {
            if (inbuf == 0 && (len >= MAX_BUFFER_SIZE || bytesIn == totalbytes)) {
                // direct copy (buffer might be null or empty)
                bytesOut += lz4.compressEstim(data, off, len)
                len = 0
            } else {
                if (buf == null) buf = ByteArray(buffer_size)
                val len1 = if (inbuf + len <= buffer_size) len else buffer_size - inbuf // to copy
                if (len1 > 0) arraycopy(data, off, buf!!, inbuf, len1)
                inbuf += len1
                len -= len1
                off += len1
                if (inbuf == buffer_size) compressFromBuffer()
            }
        }
    }