-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.js
More file actions
99 lines (79 loc) · 1.85 KB
/
Copy pathio.js
File metadata and controls
99 lines (79 loc) · 1.85 KB
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
97
98
99
// io
var _fs = require('fs');
var _path = require('path');
var _private = Symbol(); // the key for private member
class File {
}
File.exists = function(path) {
return _fs.existsSync(path);
}
File.existsAsync = function*(path) {
return yield function(returns) {
_fs.exists(path, function(exists){
returns(null, exists);
});
}
}
File.readBuffer = function(path) {
return _fs.readFileSync(path, {flag:'r'});
}
File.readBufferAsync = function*(path) {
return yield function(returns) {
_fs.readFile(path, {flag:'r'}, function(ex, data) {
returns(ex, data);
});
}
}
File.readContent = function(path, encoding) { // (path)
return _fs.readFileSync(path, encoding == null ? 'utf-8' : encoding.toString());
}
File.readContentAsync = function*(path, encoding) { // (path)
return yield function(returns) {
_fs.readFile(path, encoding == null ? 'utf-8' : encoding.toString(), function(ex, data) {
returns(ex, data);
});
}
}
class Path {
}
/**
* The separator of path in several paths.
*/
Path.delimiter = _path.delimiter;
/**
* The separator of directory in the path.
*/
Path.separator = _path.sep;
class TextWriter {
constructor(){
if(!this[_private]) this[_private] = {}; // must be first in any constructor, but after at 'super()'
}
write(value){
}
writeLine(...args){
this.write(...args);
this.write(this.newLine);
}
get encoding(){
return this[_private].encoding;
}
get newLine(){
return this[_private].newLine;
}
}
class StringWriter {
constructor(){
if(!this[_private]) this[_private] = {}; // must be first in any constructor, but after at 'super()'
this[_private].buffer = '';
}
write(value){
var buffer = this[_private].buffer;
this[_private].buffer = buffer + value;
}
toString(){
return this[_private].buffer;
}
}
exports.File = File;
exports.Path = Path;
exports.StringWriter = StringWriter;