@@ -57,7 +57,8 @@ const internalFs = {
5757 * Instead, it must be possible for it to be created newly at call time. The default is true.
5858 * @returns {Promise<string> } URL where the file was written into.
5959 */
60- writeFile ( filename , udata , create = false , exclusive = true ) {
60+ writeToFile ( filename , udata , create = false , exclusive = true ) {
61+ console . log ( Filesystem . writeFile ) ;
6162 exclusive = create ? exclusive : false ;
6263 const name = filename . split ( "/" ) . pop ( ) ;
6364
@@ -73,20 +74,22 @@ const internalFs = {
7374
7475 reject = setMessage ( reject ) ;
7576
76- if (
77- udata instanceof ArrayBuffer ||
78- Object . prototype . toString . call ( udata ) === "[object ArrayBuffer]"
79- ) {
80- // Binary data — store as base64
81- options . data = btoa ( String . fromCharCode ( ...new Uint8Array ( udata ) ) ) ;
82- options . encoding = Encoding . BASE64 ;
83- } else if ( typeof udata === "string" ) {
84- // Text data — store as UTF-8
77+ if ( typeof udata === "string" ) {
8578 options . data = udata ;
8679 options . encoding = Encoding . UTF8 ;
8780 } else {
88- reject ( "Unsupported udata type" ) ;
89- return ;
81+ function arrayBufferToBase64 ( buffer ) {
82+ let binary = "" ;
83+ const bytes = new Uint8Array ( buffer ) ;
84+ const len = bytes . byteLength ;
85+ for ( let i = 0 ; i < len ; i ++ ) {
86+ binary += String . fromCharCode ( bytes [ i ] ) ;
87+ }
88+ return btoa ( binary ) ;
89+ }
90+
91+ options . data = arrayBufferToBase64 ( udata ) ;
92+ options . encoding = Encoding . BASE64 ;
9093 }
9194
9295 Filesystem . writeFile ( options )
@@ -199,7 +202,7 @@ const internalFs = {
199202 resolve ( { data : readFileResult . data } ) ;
200203 } )
201204 . catch ( ( error ) => {
202- console . error (
205+ console . log (
203206 `Failed to Read File contents of "${ filename } ", error: ` ,
204207 error ,
205208 ) ;
@@ -552,10 +555,15 @@ function createFs(url) {
552555 if ( typeof content === "string" && encoding ) {
553556 content = await encode ( content , encoding ) ;
554557 }
555- return internalFs . writeFile ( url , content , false , false ) ;
558+ return internalFs . writeToFile ( url , content , false , false ) ;
556559 } ,
557560 createFile ( name , data ) {
558- return internalFs . writeFile ( Url . join ( url , name ) , data || "" , true , true ) ;
561+ return internalFs . writeToFile (
562+ Url . join ( url , name ) ,
563+ data || "" ,
564+ true ,
565+ true ,
566+ ) ;
559567 } ,
560568 createDirectory ( name ) {
561569 return internalFs . createDir ( url , name ) ;
0 commit comments