1 module spasm.bindings.fileapi; 2 3 import spasm.types; 4 import spasm.bindings.common; 5 import spasm.bindings.dom; 6 import spasm.bindings.html; 7 8 @safe: 9 nothrow: 10 11 struct Blob { 12 nothrow: 13 JsHandle handle; 14 alias handle this; 15 this(Handle h) { 16 this.handle = JsHandle(h); 17 } 18 auto size()() { 19 return Blob_size_Get(this.handle); 20 } 21 auto type()() { 22 return Blob_type_Get(this.handle); 23 } 24 auto slice()(int start, int end, string contentType) { 25 return Blob(Blob_slice(this.handle, start, end, contentType)); 26 } 27 auto slice()(int start, int end) { 28 return Blob(Blob_slice_0(this.handle, start, end)); 29 } 30 auto slice()(int start) { 31 return Blob(Blob_slice_1(this.handle, start)); 32 } 33 auto slice()() { 34 return Blob(Blob_slice_2(this.handle)); 35 } 36 } 37 alias BlobPart = SumType!(BufferSource, Blob, string); 38 struct BlobPropertyBag { 39 nothrow: 40 JsHandle handle; 41 alias handle this; 42 this(Handle h) { 43 this.handle = JsHandle(h); 44 } 45 static auto create() { 46 return BlobPropertyBag(spasm_add__object()); 47 } 48 void type()(string type) { 49 BlobPropertyBag_type_Set(this.handle, type); 50 } 51 auto type()() { 52 return BlobPropertyBag_type_Get(this.handle); 53 } 54 void endings()(EndingType endings) { 55 BlobPropertyBag_endings_Set(this.handle, endings); 56 } 57 auto endings()() { 58 return BlobPropertyBag_endings_Get(this.handle); 59 } 60 } 61 enum EndingType { 62 transparent, 63 native 64 } 65 struct File { 66 nothrow: 67 spasm.bindings.fileapi.Blob _parent; 68 alias _parent this; 69 this(Handle h) { 70 _parent = .Blob(h); 71 } 72 auto name()() { 73 return File_name_Get(this._parent); 74 } 75 auto lastModified()() { 76 return File_lastModified_Get(this._parent); 77 } 78 } 79 struct FileList { 80 nothrow: 81 JsHandle handle; 82 alias handle this; 83 this(Handle h) { 84 this.handle = JsHandle(h); 85 } 86 auto item()(uint index) { 87 return FileList_item_getter(this.handle, index); 88 } 89 auto length()() { 90 return FileList_length_Get(this.handle); 91 } 92 } 93 struct FilePropertyBag { 94 nothrow: 95 spasm.bindings.fileapi.BlobPropertyBag _parent; 96 alias _parent this; 97 this(Handle h) { 98 _parent = .BlobPropertyBag(h); 99 } 100 static auto create() { 101 return FilePropertyBag(spasm_add__object()); 102 } 103 void lastModified()(int lastModified) { 104 FilePropertyBag_lastModified_Set(this._parent, lastModified); 105 } 106 auto lastModified()() { 107 return FilePropertyBag_lastModified_Get(this._parent); 108 } 109 } 110 struct FileReader { 111 nothrow: 112 spasm.bindings.dom.EventTarget _parent; 113 alias _parent this; 114 this(Handle h) { 115 _parent = .EventTarget(h); 116 } 117 void readAsArrayBuffer()(scope ref Blob blob) { 118 FileReader_readAsArrayBuffer(this._parent, blob.handle); 119 } 120 void readAsBinaryString()(scope ref Blob blob) { 121 FileReader_readAsBinaryString(this._parent, blob.handle); 122 } 123 void readAsText()(scope ref Blob blob, string encoding) { 124 FileReader_readAsText(this._parent, blob.handle, encoding); 125 } 126 void readAsText()(scope ref Blob blob) { 127 FileReader_readAsText_0(this._parent, blob.handle); 128 } 129 void readAsDataURL()(scope ref Blob blob) { 130 FileReader_readAsDataURL(this._parent, blob.handle); 131 } 132 void abort()() { 133 FileReader_abort(this._parent); 134 } 135 enum ushort EMPTY = 0; 136 enum ushort LOADING = 1; 137 enum ushort DONE = 2; 138 auto readyState()() { 139 return FileReader_readyState_Get(this._parent); 140 } 141 auto result()() { 142 return FileReader_result_Get(this._parent); 143 } 144 auto error()() { 145 return FileReader_error_Get(this._parent); 146 } 147 void onloadstart()(EventHandler onloadstart) { 148 FileReader_onloadstart_Set(this._parent, onloadstart); 149 } 150 auto onloadstart()() { 151 return FileReader_onloadstart_Get(this._parent); 152 } 153 void onprogress()(EventHandler onprogress) { 154 FileReader_onprogress_Set(this._parent, onprogress); 155 } 156 auto onprogress()() { 157 return FileReader_onprogress_Get(this._parent); 158 } 159 void onload()(EventHandler onload) { 160 FileReader_onload_Set(this._parent, onload); 161 } 162 auto onload()() { 163 return FileReader_onload_Get(this._parent); 164 } 165 void onabort()(EventHandler onabort) { 166 FileReader_onabort_Set(this._parent, onabort); 167 } 168 auto onabort()() { 169 return FileReader_onabort_Get(this._parent); 170 } 171 void onerror()(EventHandler onerror) { 172 FileReader_onerror_Set(this._parent, onerror); 173 } 174 auto onerror()() { 175 return FileReader_onerror_Get(this._parent); 176 } 177 void onloadend()(EventHandler onloadend) { 178 FileReader_onloadend_Set(this._parent, onloadend); 179 } 180 auto onloadend()() { 181 return FileReader_onloadend_Get(this._parent); 182 } 183 } 184 struct FileReaderSync { 185 nothrow: 186 JsHandle handle; 187 alias handle this; 188 this(Handle h) { 189 this.handle = JsHandle(h); 190 } 191 auto readAsArrayBuffer()(scope ref Blob blob) { 192 return ArrayBuffer(FileReaderSync_readAsArrayBuffer(this.handle, blob.handle)); 193 } 194 auto readAsBinaryString()(scope ref Blob blob) { 195 return FileReaderSync_readAsBinaryString(this.handle, blob.handle); 196 } 197 auto readAsText()(scope ref Blob blob, string encoding) { 198 return FileReaderSync_readAsText(this.handle, blob.handle, encoding); 199 } 200 auto readAsText()(scope ref Blob blob) { 201 return FileReaderSync_readAsText_0(this.handle, blob.handle); 202 } 203 auto readAsDataURL()(scope ref Blob blob) { 204 return FileReaderSync_readAsDataURL(this.handle, blob.handle); 205 } 206 } 207 208 209 extern (C) uint Blob_size_Get(Handle); 210 extern (C) string Blob_type_Get(Handle); 211 extern (C) Handle Blob_slice(Handle, int, int, string); 212 extern (C) Handle Blob_slice_0(Handle, int, int); 213 extern (C) Handle Blob_slice_1(Handle, int); 214 extern (C) Handle Blob_slice_2(Handle); 215 extern (C) void BlobPropertyBag_type_Set(Handle, string); 216 extern (C) string BlobPropertyBag_type_Get(Handle); 217 extern (C) void BlobPropertyBag_endings_Set(Handle, EndingType); 218 extern (C) EndingType BlobPropertyBag_endings_Get(Handle); 219 extern (C) string File_name_Get(Handle); 220 extern (C) int File_lastModified_Get(Handle); 221 extern (C) Optional!(File) FileList_item_getter(Handle, uint); 222 extern (C) uint FileList_length_Get(Handle); 223 extern (C) void FilePropertyBag_lastModified_Set(Handle, int); 224 extern (C) int FilePropertyBag_lastModified_Get(Handle); 225 extern (C) void FileReader_readAsArrayBuffer(Handle, Handle); 226 extern (C) void FileReader_readAsBinaryString(Handle, Handle); 227 extern (C) void FileReader_readAsText(Handle, Handle, string); 228 extern (C) void FileReader_readAsText_0(Handle, Handle); 229 extern (C) void FileReader_readAsDataURL(Handle, Handle); 230 extern (C) void FileReader_abort(Handle); 231 extern (C) ushort FileReader_readyState_Get(Handle); 232 extern (C) Optional!(SumType!(string, ArrayBuffer)) FileReader_result_Get(Handle); 233 extern (C) Optional!(DOMException) FileReader_error_Get(Handle); 234 extern (C) void FileReader_onloadstart_Set(Handle, EventHandler); 235 extern (C) EventHandler FileReader_onloadstart_Get(Handle); 236 extern (C) void FileReader_onprogress_Set(Handle, EventHandler); 237 extern (C) EventHandler FileReader_onprogress_Get(Handle); 238 extern (C) void FileReader_onload_Set(Handle, EventHandler); 239 extern (C) EventHandler FileReader_onload_Get(Handle); 240 extern (C) void FileReader_onabort_Set(Handle, EventHandler); 241 extern (C) EventHandler FileReader_onabort_Get(Handle); 242 extern (C) void FileReader_onerror_Set(Handle, EventHandler); 243 extern (C) EventHandler FileReader_onerror_Get(Handle); 244 extern (C) void FileReader_onloadend_Set(Handle, EventHandler); 245 extern (C) EventHandler FileReader_onloadend_Get(Handle); 246 extern (C) Handle FileReaderSync_readAsArrayBuffer(Handle, Handle); 247 extern (C) string FileReaderSync_readAsBinaryString(Handle, Handle); 248 extern (C) string FileReaderSync_readAsText(Handle, Handle, string); 249 extern (C) string FileReaderSync_readAsText_0(Handle, Handle); 250 extern (C) string FileReaderSync_readAsDataURL(Handle, Handle);