aboutsummaryrefslogtreecommitdiff
path: root/extension/lib/decl/filewriter/filewriter.d.ts
blob: a4910d0b10e489fab164031fd2084b6506a1abd7 (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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Type definitions for File API: Writer
// Project: http://www.w3.org/TR/file-writer-api/
// Definitions by: Kon <http://phyzkit.net/> 
// Definitions: https://github.com/borisyankov/DefinitelyTyped 

/**
 * This interface provides methods to monitor the asynchronous writing of blobs to disk using progress events [PROGRESS-EVENTS] and event handler attributes.
 * This interface is specified to be used within the context of the global object (Window [HTML5]) and within Web Workers (WorkerUtils [WEBWORKERS-ED]).
 */
interface FileSaver extends EventTarget {
    /**
     * When the abort method is called, user agents must run the steps below:
     * <ol>
     * <li> If readyState == DONE or readyState == INIT, terminate this overall series of steps without doing anything else. </li>
     * <li> Set readyState to DONE. </li>
     * <li> If there are any tasks from the object's FileSaver task source in one of the task queues, then remove those tasks. </li>
     * <li> Terminate the write algorithm being processed. </li>
     * <li> Set the error attribute to a DOMError object of type "AbortError". </li>
     * <li> Fire a progress event called abort </li>
     * <li> Fire a progress event called writeend </li>
     * <li> Terminate this algorithm. </li>
     * </ol>
     */
    abort():void;

    /**
     * The blob is being written.
     * @readonly
     */
    INIT:number;

    /**
     * The object has been constructed, but there is no pending write.
     * @readonly
     */
    WRITING:number;

    /**
     * The entire Blob has been written to the file, an error occurred during the write, or the write was aborted using abort(). The FileSaver is no longer writing the blob.
     * @readonly
     */
    DONE:number;

    /**
     * The FileSaver object can be in one of 3 states. The readyState attribute, on getting, must return the current state, which must be one of the following values:
     * <ul>
     * <li>INIT</li>
     * <li>WRITING</li>
     * <li>DONE</li>
     * <ul>
     * @readonly
     */
    readyState:number;

    /**
     * The last error that occurred on the FileSaver.
     * @readonly     
     */
    error:DOMError;

    /**
     * Handler for writestart events
     */
    onwritestart:Function;

    /**
     * Handler for progress events.
     */
    onprogress:Function;

    /**
     * Handler for write events.
     */
   	onwrite:Function;

    /**
     * Handler for abort events.
     */
    onabort:Function;

    /**
     * Handler for error events.
     */
    onerror:Function;

    /**
     * Handler for writeend events.
     */
    onwriteend:Function;
}

declare var FileSaver: {
    /**
     * When the FileSaver constructor is called, the user agent must return a new FileSaver object with readyState set to INIT.
     * This constructor must be visible when the script's global object is either a Window object or an object implementing the WorkerUtils interface.
     */
    new(data:Blob): FileSaver;
}

/**
 * This interface expands on the FileSaver interface to allow for multiple write actions, rather than just saving a single Blob.
 */
interface FileWriter extends FileSaver {
    /**
     * The byte offset at which the next write to the file will occur. This must be no greater than length.
     * A newly-created FileWriter must have position set to 0.
     */
    position:number;

    /**
     * The length of the file. If the user does not have read access to the file, this must be the highest byte offset at which the user has written.
     */
    length:number;

    /**
     * Write the supplied data to the file at position. 
     * @param data The blob to write.
     */
    write(data:Blob):void;

    /**
     * Seek sets the file position at which the next write will occur.
     * @param offset If nonnegative, an absolute byte offset into the file. If negative, an offset back from the end of the file.
     */
    seek(offset:number):void;

    /**
     * Changes the length of the file to that specified. If shortening the file, data beyond the new length must be discarded. If extending the file, the existing data must be zero-padded up to the new length.
     * @param size The size to which the length of the file is to be adjusted, measured in bytes.
     */
    truncate(size:number):void;
}

/**
 * This interface lets users write, truncate, and append to files using simple synchronous calls.
 * This interface is specified to be used only within Web Workers (WorkerUtils [WEBWORKERS]).
 */
interface FileWriterSync {
    /**
     * The byte offset at which the next write to the file will occur. This must be no greater than length.
     */
    position:number;

    /**
     * The length of the file. If the user does not have read access to the file, this must be the highest byte offset at which the user has written.
     */
    length:number;

    /**
     * Write the supplied data to the file at position. Upon completion, position will increase by data.size.
     * @param data The blob to write.
     */
    write(data:Blob):void;

    /**
     * Seek sets the file position at which the next write will occur.
     * @param offset An absolute byte offset into the file. If offset is greater than length, length is used instead. If offset is less than zero, length is added to it, so that it is treated as an offset back from the end of the file. If it is still less than zero, zero is used.
     */
    seek(offset:number):void;

    /**
     * Changes the length of the file to that specified. If shortening the file, data beyond the new length must be discarded. If extending the file, the existing data must be zero-padded up to the new length.
     * Upon successful completion:
     * <ul>
     *     <li>length must be equal to size.</li>
     *     <li>position must be the lesser of
     *          <ul>
     *              <li>its pre-truncate value,</li>
     *              <li>size.</li>
     *          </ul>
     *      </li>
     *  </ul>
     * @param size The size to which the length of the file is to be adjusted, measured in bytes.
     */     
    truncate(size:number):void;
}