Writing
HomeWritingDocumentation

Downloadable Saves


Version: 1.0Published: 18th January, 2020by Morgan

Introduction

Downloadable Saves is a lightweight JavaScript library that implements save files for the web.
The library works by generating HTML files, which, when opened, will redirect users to the linked page and expose the stored data.

This process is achieved without server communication, which makes the library suitable for high-volume storage.

1. Demo


Generate a random image, then click the download button.
On opening, you will be returned to this page with the image pre-loaded


Feel free to test browser compatibility using this demo.

2. Using the library


Initialisation

The full library is contained within a single JavaScript file. To use it in your document, define a <script> element and refer to its URL in the "src" attribute.
  e.g. <script src="exampleDirectory/d-saves-v1.js"></script>

The library will initialisation automatically when the script is loaded.

Notes

The variable dSaves will be declared globally.

3. Generating save files


Generate a Blob object using dSaves.generateBlob. For example: let DataAsString = JSON.stringify({abc:"123"}); let SaveFile = dSaves.generateBlob(DataAsString);
Alternatively, download the file immediately using dSaves.download. For example: let FileName = "saveFile" let DataAsString = JSON.stringify({abc:"123"}); let SaveFile = dSaves.download(FileName,DataAsString);
Optionally, a URL can be provided as an additional argument to both functions. If not specified, the document's current location (window.location.href) is used.

In the rare case that you need parse file contents, use the function dSaves.dataFromText. For example: let FileContents = FileInput.value; let Data = dSaves.dataFromText(FileContents);

4. Retireving data


If there is data to be retrieved, the variable dSaves.hasData will be set to true, while the content is stored in dSaves.data. Ideally, both should be used when retrieving data. For example: if (dSaves.hasData) { const Data = dSaves.data; // do stuff with Data... }

5. Downloads


License

All downloadable files can be used for commerical or non-commerical purposes. Do not resell. Attribution is appreciated but not due.

Files

Complete Library: d-saves-v1.js


All possible and potential rights reserved. Should you have any concerns, feel free to contact me at Heledron@gmail.com.
Heledron