Revision 46:f16f6e0e5b69 src/pithos/content/vfs.js

b/src/pithos/content/vfs.js
1
// The Pithos File Manager Firefox Extension is funded by GRNET S.A.
2
// (http://www.grnet.gr)
3
//
4
// Copyright (c) 2009, Christos KK Loverdos, Vassilios Karakoidas.
5
// All rights reserved.
6
//
7
// Redistribution and use in source and binary forms, with or without
8
// modification, are permitted provided that the following conditions are
9
// met:
10
//
11
//   - Redistributions of source code must retain the above copyright
12
//     notice, this list of conditions and the following disclaimer.
13
//   - Redistributions in binary form must reproduce the above
14
//     copyright notice, this list of conditions and the following
15
//     disclaimer in the documentation and/or other materials provided
16
//     with the distribution.
17
//   - Neither the name of GRNET S.A. nor the names of its contributors
18
//     may be used to endorse or promote products derived from this
19
//     software without specific prior written permission.
20
//
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32

  
1 33
vfs = null;
2 34

  
3 35
function VFS() {
......
17 49
		var r = special_files[uri];
18 50
		// is not a special file
19 51
		if ( r == undefined ) {
20
			return load_directory_sync(uri, '');
52
			return load_directory_sync(uri);
21 53
		}
22 54
		
23 55
		return r(); // return the special case
......
38 70
        return null;
39 71
    }
40 72

  
73
	this.getResourceAsBinaryAsync = function(uri) {
74
        if ( this.isRemoteResource(uri) ) {
75
            var req = connection_obj.rest_request_get_inline(uri);
76
            if ( connection_obj.success(req.status) ) {
77
                return req.responseText;
78
            } else {
79
                return null;
80
            }
81
        } else if ( this.isLocalResource(uri) ) {
82
            return loadBinaryFile(uri);
83
        }
84

  
85
        return null;		
86
	}
87

  
41 88
	// Returns the metadata as a json object
42 89
	this.getResourceMetadata = function(uri) {
43 90
		var fm_obj = null;
......
100 147
			if ( vfs.isRemoteResource(uri) ) {
101 148
				// remote dir, do a json call
102 149
				var req = connection_obj.rest_request_sync(uri, '');
103
				return (new Directory(uri, JSON.parse(req.responseText)));
150
				var rt = req.responseText;
151
				if (rt.length == 0) { rt = "{}"; }
152
				return (new Directory(uri, JSON.parse(rt)));
104 153
			} else if ( vfs.isLocalResource(uri) ) {
105 154
				// local dir
106 155
				return (new Directory(uri, load_local_directory(uri)));

Also available in: Unified diff