Sfoglia il codice sorgente

Use memory stream for reading streams

Billy Barrow 2 anni fa
parent
commit
c70914560d
1 ha cambiato i file con 5 aggiunte e 6 eliminazioni
  1. 5 6
      src/lib/MarkdownView.vala

+ 5 - 6
src/lib/MarkdownView.vala

@@ -59,12 +59,11 @@ namespace GtkCommonMark {
             var reader = new GtkCommonMark.Reader(buffer, this, tag_manager);
             reader.widget_embedded.connect(on_widget_embedded);
             
-            var buffer = new uint8[1048576]; // TODO read properly in loop
-            size_t bytes_read;
-            stream.read_all(buffer, out bytes_read);
-            buffer.length = (int)bytes_read;
-            
-            reader.read_data(buffer);
+            MemoryOutputStream os = new MemoryOutputStream (null, GLib.realloc, GLib.free);
+            os.splice (stream, OutputStreamSpliceFlags.CLOSE_TARGET);
+            var data = os.steal_data();
+            data.length = (int) os.get_data_size ();
+            reader.read_data(data);
         }
 
         protected string? link_at_buffer_location(int x, int y) {