Is there a cleaner way to do this ? ```var firstCh...
# getting-started
s
Is there a cleaner way to do this ?
Copy code
var firstChunk = true
val fileChunks = flow {
	if(firstChunk) {
		val metadata = MetaData.newBuilder()
			.setPath(file.path)
			.setConvertToPdf(BoolValue.of(convertToPdf))
			.build()
		emit(FileUploadRequest.newBuilder().setMetadata(metadata).build())
		firstChunk = false
	} else {
		while(true) {
			val size = inputStream.read(chunk)
			if(size <= 0) break
			val fileChunk = FileChunk.newBuilder()
				.setData(ByteString.copyFrom(chunk, 0, size)).build()
			emit(FileUploadRequest.newBuilder().setContent(fileChunk).build())
		}
	}
}
Trying to create a flow of file bytes where the first byte is metadata of the file.
r
firstChunk
check is doing nothing because
flow
is already sequential
Copy code
flow {
		val metadata = MetaData.newBuilder()
			.setPath(file.path)
			.setConvertToPdf(BoolValue.of(convertToPdf))
			.build()
		emit(FileUploadRequest.newBuilder().setMetadata(metadata).build())

		while(true) {
			val size = inputStream.read(chunk)
			if(size <= 0) break
			val fileChunk = FileChunk.newBuilder()
				.setData(ByteString.copyFrom(chunk, 0, size)).build()
			emit(FileUploadRequest.newBuilder().setContent(fileChunk).build())
		}
}