Merge branch 'master' of http://git.roojs.com/app.Builder.js
authorAlan Knowles <alan@roojs.com>
Mon, 13 Apr 2015 09:58:26 +0000 (17:58 +0800)
committerAlan Knowles <alan@roojs.com>
Mon, 13 Apr 2015 09:58:26 +0000 (17:58 +0800)
1  2 
src/Builder4/FakeServer.vala

   * the idea is nicked from geary.
   * 
   */
 -
 +public errordomain FakeServerError {
 +              FILE_DOES_NOT_EXIST
 +      }
 +      
  public class FakeServer : Object
  {
 +      
        WebKit.WebView view;
        
        public FakeServer(WebKit.WebView wkview)
                var  file = File.new_for_path ( GLib.Environment.get_home_dir() + "/gitlive" + request.get_path());
                if (!file.query_exists()) {
                        print("Skip file missing = %s/gitlive%s\n", GLib.Environment.get_home_dir() , request.get_path());
 +                      request.finish_error(new FakeServerError.FILE_DOES_NOT_EXIST ("My error msg"));
                        return;
                }
-                       
-               var stream = file.read();
                var info = file.query_info(
                                 "standard::*",
                                FileQueryInfoFlags.NONE
                );
+               
+               string data;
+               size_t length;
+               GLib.FileUtils.get_contents(file.get_path(), out data, out length);
+               
+               var stream = new MemoryInputStream.from_data (data,  GLib.free);
+               
+               // we could cache these memory streams... so no need to keep reading from disk...
+               // then what happens if file get's updated - neet to check the data against the cache..
+               
+               
                print("Sending %s (%s:%s)\n", request.get_path(), info.get_size().to_string(), info.get_content_type());
                
                request.finish (  stream, info.get_size()  , info.get_content_type());