Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/utils/platforms/xulrunner/lib/io-platform.js
blob: 5c2ce620c9562560e97535f1c5a33f55020b79b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const Cc = Components.classes;
const Ci = Components.interfaces;

var IO = exports.IO = function(inputStream, outputStream) {
    this.inputStream = inputStream;
    this.outputStream = outputStream;
}

IO.prototype.read = function(length) {
    return this.inputStream(length);
}

IO.prototype.write = function(object) {
    this.outputStream(object);
}

IO.prototype.flush = function() {
}

IO.prototype.close = function() {
}

IO.prototype.isatty = function () {
    return false;
}



exports.TextInputStream = function (raw, lineBuffering, buffering, charset, options) {
    var stream;

//    if (charset === undefined) {
//    if (buffering === undefined)

    stream = raw.inputStream;
    stream.QueryInterface(Ci.nsILineInputStream);

    var self = this;

    self.readLine = function () {
//        var line = stream.readLine();
//        if (line === null)
//            return '';
//        return String(line) + "\n";
    };

    self.iter = function () {
        return self;
    };

    self.next = function () {
//        var line = stream.readLine();
//        if (line === null)
//            throw new Error("StopIteration");
//        return line;
    };

    self.input = function () {
        throw "NYI";
    };

    self.readLines = function () {
        var line = {},
            lines = [],
            hasmore;
        do {
          hasmore = stream.readLine(line);
          lines.push(line.value);
        } while(hasmore);
        return lines;
    };

    self.read = function () {
        return self.readLines().join("\n");
    };

    self.readInto = function (buffer) {
        throw "NYI";
    };

    self.close = function () {
        stream.close();
    };
};

exports.TextIOWrapper = function (raw, mode, lineBuffering, buffering, charset, options) {
    if (mode.update) {
        return new exports.TextIOStream(raw, lineBuffering, buffering, charset, options);
    } else if (mode.write || mode.append) {
        return new exports.TextOutputStream(raw, lineBuffering, buffering, charset, options);
    } else if (mode.read) {
        return new exports.TextInputStream(raw, lineBuffering, buffering, charset, options);
    } else {
        throw new Error("file must be opened for read, write, or append mode.");
    }
};