Skip to content

aldrin112602/file-system-JS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation

To use file-system-JS, include the fileSystem.js script in your HTML file:

<script src="fileSystem.js"></script>

Usage

Common Functions

Initialize the file system object:

const fs = new FileSystem();
readFileAsDataURL(file)

Read a file and return its data as a base64-encoded data URL.

Example:

fs.readFileAsDataURL("image.png")
  .then(function(data) {
    console.log(data); // base64 String
  });

To read a file from an element:

<input type="file" id="fileInput">
const fileInput = document.getElementById('fileInput');
fileInput.addEventListener('change', async function() {
  const data = await fs.readFileAsDataURL(fileInput.files[0]);
  console.log(data); // base64 String
});

readFile(file) Read a file and return its content as text.

Example:

fs.readFile('main.js')
  .then(function(data) {
    console.log(data);
  });

You can also use async/await:

async function readTextFile() {
  const content = await fs.readFile('sample.txt');
  console.log(content);
}
createFile(content, type, filename)

Create a file with the specified content, MIME type, and filename.

Example:

fs.createFile("Sample Text", 'text/plain', 'sample.txt');
fs.createFile('console.log("Hello, world!")', 'text/javascript', 'main.js');
License
This project is licensed under the MIT License - see the LICENSE file for details.

Releases

No releases published

Packages

No packages published