Skip to content

Commit

Permalink
v1.2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
mastashake08 committed Oct 12, 2023
1 parent aa069d0 commit 4ef9106
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
22 changes: 13 additions & 9 deletions ShakeFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class ShakeFile {

// write our file
console.log(this.obj)
let my_uint8_array = Uint8Array.from(this.obj.value, c => c.charCodeAt(0));
await writableStream.write(new Blob([my_uint8_array], {type: 'text/plain'}));
var enc = new TextEncoder();
var data = enc.encode(this.obj.value)
console.log(data)
await writableStream.write(new Blob([data]));

// close the file and write the contents to disk.
await writableStream.close();
Expand All @@ -37,10 +39,11 @@ class ShakeFile {

// create a FileSystemWritableFileStream to write to
const writableStream = await newHandle.createWritable();

let my_uint8_array = Uint8Array.from(this.obj.value, c => c.charCodeAt(0));

await writableStream.write(new Blob([my_uint8_array], {type: this.file.type}));

// write our file
console.log(this.obj)
await writableStream.write(new Blob(this.obj.value));

// close the file and write the contents to disk.
await writableStream.close();
Expand Down Expand Up @@ -194,10 +197,10 @@ class ShakeFile {
this.obj.style.height = '300px'
this.obj.value = dataUrl
const save = document.createElement('button')
save.innerHTML = 'Save File'
save.innerHTML = 'Save Text File'
console.log('save')
save.onclick = () => {
this.saveBinaryFile()
this.saveFile()
}
this.mainDiv.appendChild(this.obj)

Expand All @@ -209,6 +212,7 @@ class ShakeFile {
reader.readAsBinaryString(file)
reader.onload = () => {
const dataUrl = reader.result
console.log(dataUrl)
this.obj = document.createElement('textarea')
this.obj.disabled = false
this.obj.style.resize = 'both'
Expand All @@ -217,10 +221,10 @@ class ShakeFile {
this.obj.value = dataUrl
this.mainDiv.appendChild(this.obj)
const save = document.createElement('button')
save.innerHTML = 'Save File'
save.innerHTML = 'Save Binary File'
console.log('save')
save.onclick = () => {
this.saveFile()
this.saveBinaryFile()
}
this.obj.after(save)
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shake-file",
"version": "1.2.8",
"version": "1.2.9",
"description": "Pure Javascript package for using the File System API",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 4ef9106

Please sign in to comment.