Skip to content

Commit 90b79b1

Browse files
committed
Dump sync stream to file
1 parent 15a7674 commit 90b79b1

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

core/src/commonMain/kotlin/com/powersync/sync/SyncStream.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ import kotlinx.coroutines.flow.emitAll
5454
import kotlinx.coroutines.flow.flow
5555
import kotlinx.coroutines.launch
5656
import kotlinx.coroutines.withContext
57+
import kotlinx.io.Sink
58+
import kotlinx.io.buffered
59+
import kotlinx.io.files.Path
60+
import kotlinx.io.files.SystemFileSystem
5761
import kotlinx.serialization.SerialName
5862
import kotlinx.serialization.Serializable
5963
import kotlinx.serialization.json.JsonObject
@@ -258,7 +262,9 @@ internal class SyncStream(
258262

259263
private suspend fun streamingSyncIteration() {
260264
coroutineScope {
261-
val iteration = ActiveIteration(this)
265+
val file = SystemFileSystem.sink(Path("/Users/simon/test.bin")).buffered()
266+
267+
val iteration = ActiveIteration(this, dumpSyncLines = file)
262268

263269
try {
264270
iteration.start()
@@ -267,6 +273,7 @@ internal class SyncStream(
267273
// clean up resources.
268274
withContext(NonCancellable) {
269275
iteration.stop()
276+
file.close()
270277
}
271278
}
272279
}
@@ -276,6 +283,7 @@ internal class SyncStream(
276283
val scope: CoroutineScope,
277284
var fetchLinesJob: Job? = null,
278285
var credentialsInvalidation: Job? = null,
286+
var dumpSyncLines: Sink
279287
) {
280288
suspend fun start() {
281289
control("start", JsonUtil.json.encodeToString(params))
@@ -360,7 +368,10 @@ internal class SyncStream(
360368
}
361369
}
362370
}
363-
Instruction.DidCompleteSync -> status.update { copy(downloadError=null) }
371+
Instruction.DidCompleteSync -> {
372+
dumpSyncLines.flush()
373+
status.update { copy(downloadError=null) }
374+
}
364375
is Instruction.UnknownInstruction -> {
365376
throw PowerSyncException("Unknown instruction received from core extension: ${instruction.raw}", null)
366377
}

0 commit comments

Comments
 (0)