├── sample ├── build.hxml ├── output │ ├── index.html │ └── FileSaverSample.js └── Sample.hx ├── haxe-FileSaver.zip ├── .gitmodules ├── js └── html │ └── FileSaver.hx ├── haxelib.json ├── .gitignore ├── LICENSE ├── README.md └── .gitattributes /sample/build.hxml: -------------------------------------------------------------------------------- 1 | -lib FileSaver 2 | -main Sample 3 | -js output/FileSaverSample.js -------------------------------------------------------------------------------- /haxe-FileSaver.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hamaluik/haxe-FileSaver/master/haxe-FileSaver.zip -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "sample/output/FileSaver"] 2 | path = sample/output/FileSaver 3 | url = git@github.com:eligrey/FileSaver.js.git 4 | -------------------------------------------------------------------------------- /js/html/FileSaver.hx: -------------------------------------------------------------------------------- 1 | package js.html; 2 | 3 | import js.html.Blob; 4 | 5 | @:native('window') 6 | extern class FileSaver { 7 | public static function saveAs(data:Blob, filename:String, ?disableAutoBOM:Bool):Void; 8 | } -------------------------------------------------------------------------------- /sample/output/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | FileSaver Sample 4 | 5 | 6 | 7 |

FileSaver Sample

8 |

to download the "The Charge of the Light Brigade" by Alfred Lord Tennyson.

9 | 10 | 11 | -------------------------------------------------------------------------------- /haxelib.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FileSaver", 3 | "url" : "https://github.com/FuzzyWuzzie/haxe-FileSaver", 4 | "license": "MIT", 5 | "tags": ["js"], 6 | "description": "Haxe externs for the FileSaver.js library (for saving files from the browser).", 7 | "version": "1.0.0", 8 | "releasenote": "Initial release, everything is working correctly.", 9 | "contributors": ["FuzzyWuzzie"], 10 | "dependencies": {} 11 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Windows ### 2 | # Windows image file caches 3 | Thumbs.db 4 | ehthumbs.db 5 | 6 | # Folder config file 7 | Desktop.ini 8 | 9 | # Recycle Bin used on file shares 10 | $RECYCLE.BIN/ 11 | 12 | # Windows Installer files 13 | *.cab 14 | *.msi 15 | *.msm 16 | *.msp 17 | 18 | # Windows shortcuts 19 | *.lnk 20 | 21 | 22 | ### OSX ### 23 | .DS_Store 24 | .AppleDouble 25 | .LSOverride 26 | 27 | # Icon must end with two \r 28 | Icon 29 | 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | 49 | 50 | ### Linux ### 51 | *~ 52 | 53 | # KDE directory preferences 54 | .directory 55 | 56 | # Linux trash folder which might appear on any partition or disk 57 | .Trash-* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Kenton Hamaluik 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # haxe-FileSaver 2 | [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/FuzzyWuzzie/haxe-FileSaver/blob/master/LICENSE) 3 | 4 | Haxe externs for [eligrey/FileSaver.js](https://github.com/eligrey/FileSaver.js) 5 | 6 | ## Supported browsers 7 | From [eligrey/FileSaver.js#supported-browsers](https://github.com/eligrey/FileSaver.js#supported-browsers): 8 | 9 | | Browser | Constructs as | Filenames | Max Blob Size | Dependencies | 10 | | ------------------ | ------------- | --------- | ------------- | ------------ | 11 | | Firefox 20+ | Blob | Yes | 800 MiB | None | 12 | | Firefox < 20 | data: URI | No | n/a | [Blob.js][1] | 13 | | Chrome | Blob | Yes | [500 MiB][2] | None | 14 | | Chrome for Android | Blob | Yes | [500 MiB][2] | None | 15 | | IE 10+ | Blob | Yes | 600 MiB | None | 16 | | Opera 15+ | Blob | Yes | 500 MiB | None | 17 | | Opera < 15 | data: URI | No | n/a | [Blob.js][1] | 18 | | Safari 6.1+* | Blob | No | ? | None | 19 | | Safari < 6 | data: URI | No | n/a | [Blob.js][1] | 20 | 21 | ## Syntax 22 | 23 | ```haxe 24 | FileSaver.saveAs(blob:js.html.Blob, fileName:String, disableAutoBOM:Bool = false); 25 | ``` 26 | 27 | ## Examples 28 | 29 | ### Saving text 30 | 31 | ```haxe 32 | var blob:js.html.Blob = new js.html.Blob(["Hello world!"], { type: "text/plain;charset=utf-8" }); 33 | FileSaver.saveAs(blob, "hello world.txt"); 34 | ``` 35 | 36 | ### Live Sample 37 | 38 | A [live sample](http://hamaluik.github.io/haxe-FileSaver/) is available, which provides you with a poem! 39 | 40 | [1]: https://github.com/eligrey/Blob.js 41 | [2]: https://code.google.com/p/chromium/issues/detail?id=375297 42 | -------------------------------------------------------------------------------- /sample/Sample.hx: -------------------------------------------------------------------------------- 1 | import js.html.Element; 2 | import js.html.Blob; 3 | import js.html.FileSaver; 4 | 5 | using StringTools; 6 | 7 | class Sample { 8 | static public function main() { 9 | var btn:Element = js.Browser.document.getElementById("downloadBtn"); 10 | btn.addEventListener("click", function() { 11 | var blob:Blob = new Blob([" 12 | # The Charge of the Light Brigade 13 | by Alfred Lord Tennyson 14 | 15 | Half a league, half a league, 16 | Half a league onward, 17 | All in the valley of Death 18 | Rode the six hundred. 19 | \"Forward the Light Brigade! 20 | Charge for the guns!\" he said. 21 | Into the valley of Death 22 | Rode the six hundred. 23 | 24 | Forward, the Light Brigade!\" 25 | Was there a man dismay'd? 26 | Not tho' the soldier knew 27 | Some one had blunder'd. 28 | Theirs not to make reply, 29 | Theirs not to reason why, 30 | Theirs but to do and die. 31 | Into the valley of Death 32 | Rode the six hundred. 33 | 34 | Cannon to right of them, 35 | Cannon to left of them, 36 | Cannon in front of them 37 | Volley'd and thunder'd; 38 | Storm'd at with shot and shell, 39 | Boldly they rode and well, 40 | Into the jaws of Death, 41 | Into the mouth of hell 42 | Rode the six hundred. 43 | 44 | Flash'd all their sabres bare, 45 | Flash'd as they turn'd in air 46 | Sabring the gunners there, 47 | Charging an army, while 48 | All the world wonder'd. 49 | Plunged in the battery-smoke 50 | Right thro' the line they broke; 51 | Cossack and Russian 52 | Reel'd from the sabre-stroke 53 | Shatter'd and sunder'd. 54 | Then they rode back, but not, 55 | Not the six hundred. 56 | 57 | Cannon to right of them, 58 | Cannon to left of them, 59 | Cannon behind them 60 | Volley'd and thunder'd; 61 | Storm'd at with shot and shell, 62 | While horse and hero fell, 63 | They that had fought so well 64 | Came thro' the jaws of Death, 65 | Back from the mouth of hell, 66 | All that was left of them, 67 | Left of six hundred. 68 | 69 | When can their glory fade? 70 | O the wild charge they made! 71 | All the world wonder'd. 72 | Honor the charge they made! 73 | Honor the Light Brigade, 74 | Noble six hundred! 75 | ".trim()], 76 | {type: "text/markdown;charset=utf-8"}); 77 | FileSaver.saveAs(blob, "The Charge of the Light Brigade.md"); 78 | }); 79 | } 80 | } -------------------------------------------------------------------------------- /sample/output/FileSaverSample.js: -------------------------------------------------------------------------------- 1 | (function (console) { "use strict"; 2 | var HxOverrides = function() { }; 3 | HxOverrides.cca = function(s,index) { 4 | var x = s.charCodeAt(index); 5 | if(x != x) return undefined; 6 | return x; 7 | }; 8 | HxOverrides.substr = function(s,pos,len) { 9 | if(pos != null && pos != 0 && len != null && len < 0) return ""; 10 | if(len == null) len = s.length; 11 | if(pos < 0) { 12 | pos = s.length + pos; 13 | if(pos < 0) pos = 0; 14 | } else if(len < 0) len = s.length + len - pos; 15 | return s.substr(pos,len); 16 | }; 17 | var Sample = function() { }; 18 | Sample.main = function() { 19 | var btn = window.document.getElementById("downloadBtn"); 20 | btn.addEventListener("click",function() { 21 | var blob = new Blob([StringTools.trim("\r\n# The Charge of the Light Brigade\r\nby Alfred Lord Tennyson\r\n\r\n Half a league, half a league,\r\n Half a league onward,\r\n All in the valley of Death\r\n Rode the six hundred.\r\n \"Forward the Light Brigade!\r\n Charge for the guns!\" he said.\r\n Into the valley of Death\r\n Rode the six hundred.\r\n \r\n Forward, the Light Brigade!\"\r\n Was there a man dismay'd?\r\n Not tho' the soldier knew\r\n Some one had blunder'd.\r\n Theirs not to make reply,\r\n Theirs not to reason why,\r\n Theirs but to do and die.\r\n Into the valley of Death\r\n Rode the six hundred.\r\n \r\n Cannon to right of them,\r\n Cannon to left of them,\r\n Cannon in front of them\r\n Volley'd and thunder'd;\r\n Storm'd at with shot and shell,\r\n Boldly they rode and well,\r\n Into the jaws of Death,\r\n Into the mouth of hell\r\n Rode the six hundred.\r\n \r\n Flash'd all their sabres bare,\r\n Flash'd as they turn'd in air\r\n Sabring the gunners there,\r\n Charging an army, while\r\n All the world wonder'd.\r\n Plunged in the battery-smoke\r\n Right thro' the line they broke;\r\n Cossack and Russian\r\n Reel'd from the sabre-stroke\r\n Shatter'd and sunder'd.\r\n Then they rode back, but not,\r\n Not the six hundred.\r\n \r\n Cannon to right of them,\r\n Cannon to left of them,\r\n Cannon behind them\r\n Volley'd and thunder'd;\r\n Storm'd at with shot and shell,\r\n While horse and hero fell,\r\n They that had fought so well\r\n Came thro' the jaws of Death,\r\n Back from the mouth of hell,\r\n All that was left of them,\r\n Left of six hundred.\r\n \r\n When can their glory fade?\r\n O the wild charge they made!\r\n All the world wonder'd.\r\n Honor the charge they made!\r\n Honor the Light Brigade,\r\n Noble six hundred!\r\n\t\t\t")],{ type : "text/markdown;charset=utf-8"}); 22 | window.saveAs(blob,"The Charge of the Light Brigade.md"); 23 | }); 24 | }; 25 | var StringTools = function() { }; 26 | StringTools.isSpace = function(s,pos) { 27 | var c = HxOverrides.cca(s,pos); 28 | return c > 8 && c < 14 || c == 32; 29 | }; 30 | StringTools.ltrim = function(s) { 31 | var l = s.length; 32 | var r = 0; 33 | while(r < l && StringTools.isSpace(s,r)) r++; 34 | if(r > 0) return HxOverrides.substr(s,r,l - r); else return s; 35 | }; 36 | StringTools.rtrim = function(s) { 37 | var l = s.length; 38 | var r = 0; 39 | while(r < l && StringTools.isSpace(s,l - r - 1)) r++; 40 | if(r > 0) return HxOverrides.substr(s,0,l - r); else return s; 41 | }; 42 | StringTools.trim = function(s) { 43 | return StringTools.ltrim(StringTools.rtrim(s)); 44 | }; 45 | Sample.main(); 46 | })(typeof console != "undefined" ? console : {log:function(){}}); 47 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Apply native OS line-endings on checkout of these files... 2 | *.boo text 3 | *.c text 4 | *.cginc text 5 | *.config text 6 | *.contentproj text 7 | *.cpp text 8 | *.cs text 9 | *.css text 10 | *.dae text 11 | *.DAE text 12 | *.dtd text 13 | *.fx text 14 | *.glsl text 15 | *.h text 16 | *.htm text 17 | *.html text 18 | *.inc text 19 | *.ini text 20 | *.js text 21 | *.JSFL text 22 | *.jsfl text 23 | *.json text 24 | *.log text 25 | *.md text 26 | *.mel text 27 | *.php text 28 | *.shader text 29 | *.txt text 30 | *.TXT text 31 | *.xaml text 32 | *.xml text 33 | *.xsd text 34 | .gitattributes text 35 | .gitignore text 36 | COPYING text 37 | INSTALL* text 38 | KEYS* text 39 | LICENSE* text 40 | NEWS* text 41 | NOTICE* text 42 | README* text 43 | TODO* text 44 | WHATSNEW* text 45 | 46 | # Apply Unix-style LF line-endings on checkout of these files... 47 | *.meta text eol=lf 48 | *.sh text eol=lf 49 | *.vspscc text eol=lf 50 | .htaccess text eol=lf 51 | 52 | # Apply Windows/DOS-style CR-LF line-endings on checkout of these files... 53 | *.bat text eol=crlf 54 | *.cmd text eol=crlf 55 | *.csproj text eol=crlf 56 | *.sln text eol=crlf 57 | *.user text eol=crlf 58 | *.vcproj text eol=crlf 59 | 60 | # No end-of-line conversions are applied (i.e., "-text -diff") to these files... 61 | *.7z binary 62 | *.ai binary 63 | *.anim binary 64 | *.apk binary 65 | *.asset binary 66 | *.bin binary 67 | *.bmp binary 68 | *.BMP binary 69 | *.com binary 70 | *.COM binary 71 | *.controller binary 72 | *.cubemap binary 73 | *.dex binary 74 | *.dll binary 75 | *.DLL binary 76 | *.dylib binary 77 | *.eps binary 78 | *.exe binary 79 | *.EXE binary 80 | *.exr binary 81 | *.fbx binary 82 | *.FBX binary 83 | *.fla binary 84 | *.flare binary 85 | *.flv binary 86 | *.gif binary 87 | *.guiskin binary 88 | *.gz binary 89 | *.ht binary 90 | *.ico binary 91 | *.jpeg binary 92 | *.jpg binary 93 | *.keystore binary 94 | *.mask binary 95 | *.mat binary 96 | *.mb binary 97 | *.mp3 binary 98 | *.mp4 binary 99 | *.mpg binary 100 | *.ogg binary 101 | *.PCX binary 102 | *.pcx binary 103 | *.pdb binary 104 | *.pdf binary 105 | *.physicMaterial binary 106 | *.physicmaterial binary 107 | *.png binary 108 | *.prefab binary 109 | *.ps binary 110 | *.psd binary 111 | *.qt binary 112 | *.so binary 113 | *.swf binary 114 | *.tga binary 115 | *.tif binary 116 | *.tiff binary 117 | *.ttf binary 118 | *.TTF binary 119 | *.unity binary 120 | *.unitypackage binary 121 | *.unityPackage binary 122 | *.wav binary 123 | *.wmv binary 124 | *.zip binary 125 | *.ZIP binary --------------------------------------------------------------------------------