Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/utils/platforms/default/lib/file-platform.js
blob: ddef889bf5ffbf78bb0bb21e2b2293dd4ad14210 (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
// File: default

var IO = require("./io").IO;

var File = exports.File = function(path) {
    this.path = path;
}
File.prototype = new IO();

File.prototype.read = function() {
    var result = narwhalReadFile(this.path);
    if (!result)
        throw new Error("Couldn't read file " + path);
    return result;
}

exports.SEPARATOR = '/';

exports.canonical = function(path) {
    var original;

    do {
        original = path;
        path = path
            .replace(/[^\/]+\/\.\.\//g, "")
            .replace(/([^\.])\.\//g, "$1")
            .replace(/^\.\//g, "")
            .replace(/\/\/+/g, "/");
    } while (path !== original);
        
    return path;
}