/
textstream.d.ts
146 lines (144 loc) · 4.96 KB
/
textstream.d.ts
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/// <reference path="./file.d.ts" />
interface TextStream {
/**
* Creates a textStream.
*
* ```javascript
* // The file does not have to exist
* var myStream = new TextStream( 'PROJECT/my-streamed-file.js', 'write' );
* // Creates the file if it does not exist
* myStream.write( 'Hello '+ Date.now() +' !\n' );
* // Important to close the stream every time.
* myStream.close();
* ```
*
* @param file Binary text file to reference. The file does not to exist
* @param mode Opens a stream in `Write`, `Read` or `Overwrite` mode
* @param charset (default: 7) Character set of the text. See more details on [charset](http://doc.wakanda.org/home2.en.html#/Files-and-Folders/TextStream/TextStream.301-684310.en.html)
*/
new (file: String, mode: String, charset?: Number): WAKTextStreamInstance;
/**
* Creates a textStream.
*
* ```javascript
* // The file does not have to exist
* var myFile = new File( 'PROJECT/my-streamed-file.js' );
* var myStream = new TextStream( file, 'write' );
* // Creates the file if it does not exist
* myStream.write( 'Hello '+ Date.now() +' !\n' );
* // Important to close the stream every time.
* myStream.close();
* ```
*
* @param file Binary text file to reference. The file does not to exist
* @param mode Opens a stream in `Write`, `Read` or `Overwrite` mode
* @param charset (default: 7) Character set of the text. See more details on [charset](http://doc.wakanda.org/home2.en.html#/Files-and-Folders/TextStream/TextStream.301-684310.en.html)
*/
new (file: WAKFileInstance, mode: String, charset?: Number): WAKTextStreamInstance;
}
interface WAKTextStreamInstance {
/**
* Closes the file referenced in the TextStream object.
*
* ```javascript
* var myFile = new File( 'PROJECT/my-streamed-file.js' );
* var myStream = new TextStream( file, 'write' );
* myStream.write( 'Hello '+ Date.now() +' !\n' );
* // Important to close the stream every time.
* myStream.close();
* ```
*/
close(): void;
/**
* Checks if the the cursor position is after the last character of the file referenced in the TextStream object.
*
* ```javascript
* var myStream = new TextStream( 'PROJECT/bootstrap.js', 'Read' );
* // Is end of file reached ?
* while( !myStream.end() ){
* console.log( myStream.read( 10 ) );
* }
* // Important to close the stream every time.
* myStream.close();
* ```
*
* @returns `true` if the cursor position is at the end of file, `false` otherwise.
*/
end(): Boolean;
/**
* Saves the contents of the TextStream buffer to the disk file.
*/
flush(): void;
/**
* Get the current cursor position in the text stream.
*
* ```javascript
* var myStream = new TextStream( 'PROJECT/bootstrap.js', 'Read' );
* while( !myStream.end() ){
* myStream.read( 10 );
* console.log( myStream.getPos() );
* // 10, 20, 30, ...
* }
* // Important to close the stream every time.
* myStream.close();
* ```
*/
getPos(): Number;
/**
* Get the current text stream size.
*
* ```javascript
* var myStream = new TextStream( 'PROJECT/bootstrap.js', 'Read' );
* console.log( myStream.getSize() );
* // 183
* // Important to close the stream every time.
* myStream.close();
* ```
*/
getSize(): Number;
/**
* Reads bytes from the text stream.
*
* ```javascript
* var myStream = new TextStream( 'PROJECT/bootstrap.js', 'Read' );
* while( !myStream.end() ){
* // Read the next 10 bytes and moves the cursor position accordingly
* console.log( myStream.read( 10 ) );
* }
* // Important to close the stream every time.
* myStream.close();
* ```
*
* @param nbBytes (default: `TextStream.getSize()`) Number of bytes to read
*/
read(nbBytes?: Number): String;
/**
* Set the cursor position to the beginning of the TextStream.
*
* ```javascript
* var myStream = new TextStream( 'PROJECT/bootstrap.js', 'Read' );
* console.log( 'Start: '+ myStream.getPos() );
* myStream.read(20);
* console.log( 'After read: '+ myStream.getPos() );
* myStream.rewind();
* console.log( 'After rewind: '+ myStream.getPos() );
* // Important to close the stream every time.
* myStream.close();
* ```
*/
rewind(): void;
/**
* Writes the text in the TextStream.
*
* ```javascript
* var myFile = new File( 'PROJECT/my-streamed-file.js' );
* var myStream = new TextStream( file, 'write' );
* myStream.write( 'Hello '+ Date.now() +' !\n' );
* // Important to close the stream every time.
* myStream.close();
* ```
*
* @param text String to write in the TextStream
*/
write(text: String): void;
}