diff --git a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/EnvelopeParts.kt b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/EnvelopeParts.kt index ca4efea4..0a8a207d 100644 --- a/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/EnvelopeParts.kt +++ b/dataforge-io/src/commonMain/kotlin/hep/dataforge/io/EnvelopeParts.kt @@ -17,6 +17,9 @@ object EnvelopeParts { const val PARTS_DATA_TYPE = "envelope.parts" } +/** + * Append multiple serialized envelopes to the data block. Previous data is erased if it was present + */ fun EnvelopeBuilder.parts(formatFactory: EnvelopeFormatFactory, envelopes: Collection) { dataType = PARTS_DATA_TYPE meta { @@ -36,7 +39,10 @@ fun EnvelopeBuilder.parts(formatFactory: EnvelopeFormatFactory, envelopes: Colle fun EnvelopeBuilder.parts(formatFactory: EnvelopeFormatFactory, builder: suspend SequenceScope.() -> Unit) = parts(formatFactory, sequence(builder).toList()) -fun Envelope.parts(io: IOPlugin = Global.plugins.fetch(IOPlugin)): Sequence { +/** + * If given envelope supports multipart data, return a sequence of those parts (could be empty). Otherwise return null. + */ +fun Envelope.parts(io: IOPlugin = Global.plugins.fetch(IOPlugin)): Sequence? { return when (dataType) { PARTS_DATA_TYPE -> { val size = meta[SIZE_KEY].int ?: error("Unsized parts not supported yet") @@ -55,6 +61,6 @@ fun Envelope.parts(io: IOPlugin = Global.plugins.fetch(IOPlugin)): Sequence emptySequence() + else -> null } }