Skip to content
Sign upLog in
← Back to Community

How to edit files/blobs in JavaScript and then export it

Profile icon
Coder2195

The scratch GUI is a great GUI with its exporting and importing with sb3 files

I want to know how does scratch do it

According to stack overflow they say you can’t edit files

But how does scratch GUI do it

Voters
Profile icon
Coder2195
Comments
hotnewtop
Profile icon
Coder100

Simple
after you obtain the file, convert it into a blob, and then:
https://developer.mozilla.org/en-US/docs/Web/API/Blob/text

and then:
https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL

or however else you find you want to do

Profile icon
Coder2195

@Coder100
no I meant for example I have some text
How do I write that to a txt file and export it

Profile icon
Coder100

@Coder2195Text
you DON't write it to any file, you just make a new blob that can be downloaded

did you forget you can't make any files lol

Profile icon
Coder2195

@Coder100
hmmm so how do I convert a string to a blob

Profile icon
Coder100
Profile icon
Coder2195

@Coder100
I take a look
I gtg anyways

Profile icon
notGilbert

@Coder2195Text

you’ll need to serialize whatever you need to save into a string format, i find JSON.stringify really useful for that

then you can download the contents as a blob

alternatively if you only need to store it in the browser you can use IndexedDB or localStorage to store that JSON string

Profile icon
Coder100

hmm did he not assert that the type was a string tho

@notGilbert

Profile icon
HankFried

Solution2Pass has the best answer for pro Cisco CCNP Enterprise 300-415 Practice Test with assurance of outcome in absolute first endeavor. Such an appealing deal recognizes us among our opponents and draw us nearer to the aggressive IT experts who need to help up their vocations fully supported by the best Cisco IT affirmations.

https://www.solution2pass.com/300-415-questions.html

Information has forever been the genuine power and Solution2Pass targets conferring information to you in an intuitive and imaginative manner. Solution2Pass Cisco CCNP Enterprise Study Guide has been formulated as an effectively open, illuminating and befitting wellspring of information to clean your abilities and take care of your test needs. This simple substance, organized into questions and answers makes certain to grant you a remarkable test achievement.

Profile icon
Coder2195

@HankFried
This is a coding place not a advertise place

Profile icon
tussiez

If you're using NodeJS:

const fs = require('fs'); let someTextFile = fs.readFileSync('file.txt','utf8'); // the file // change the file fs.writeFile('file.txt','Hey want a rickroll');
Profile icon
notGilbert

you cant edit files directly on the disk, however, you can upload modify, and download

you can save the data into a JSON or a . file to export data

do you have a sb3 file so i can look inside of it?

Profile icon
Coder2195

@notGilbert
no I was giving an example
How does scratch modify files inside the page and then export it

Profile icon
notGilbert

@Coder2195Text

scratch seems to use blobs to download the data, and using canvas to modify sprites (i think)

it doesnt modify any files, it just decodes it and reads and the downloads a serializable format when requested

Profile icon
notGilbert

@Coder2195Text

what data are you trying to store / export?