+ char buffer[4096];
+
+ while (G_LIKELY (!tny_stream_is_eos (cache_stream))) {
+ gssize nb_read;
+
+ nb_read = tny_stream_read (cache_stream, buffer, sizeof (buffer));
+ if (G_UNLIKELY (nb_read < 0)) {
+ break;
+ } else if (G_LIKELY (nb_read > 0)) {
+ gssize nb_written = 0;
+
+ while (G_UNLIKELY (nb_written < nb_read)) {
+ gssize len;
+
+ gdk_threads_enter ();
+ len = tny_stream_write (fidata->output_stream, buffer + nb_written,
+ nb_read - nb_written);
+ gdk_threads_leave ();
+ if (G_UNLIKELY (len < 0))
+ break;
+ nb_written += len;
+ }
+ }
+ }
+ gdk_threads_enter ();