5
5
*/
6
6
7
7
mergeInto ( LibraryManager . library , {
8
- $FS__deps : [ '$randomFill' , '$PATH' , '$PATH_FS' , '$TTY' , '$MEMFS' , '$asyncLoad' ,
8
+ $FS__deps : [ '$randomFill' , '$PATH' , '$PATH_FS' , '$TTY' , '$MEMFS' ,
9
+ '$FS_createPreloadedFile' ,
10
+ '$FS_modeStringToFlags' ,
11
+ '$FS_getMode' ,
9
12
'$intArrayFromString' ,
10
13
'$stringToUTF8Array' ,
11
14
'$lengthBytesUTF8' ,
@@ -88,6 +91,7 @@ Object.defineProperties(FSNode.prototype, {
88
91
}
89
92
});
90
93
FS.FSNode = FSNode;
94
+ FS.createPreloadedFile = FS_createPreloadedFile;
91
95
FS.staticInit();` +
92
96
#if USE_CLOSURE_COMPILER
93
97
// Declare variable for Closure, FS.createPreloadedFile() below calls Browser.handledByPreloadPlugin()
@@ -293,25 +297,6 @@ FS.staticInit();` +
293
297
//
294
298
// permissions
295
299
//
296
- flagModes : {
297
- // Extra quotes used here on the keys to this object otherwise jsifier will
298
- // erase them in the process of reading and then writing the JS library
299
- // code.
300
- '"r"' : { { { cDefs . O_RDONLY } } } ,
301
- '"r+"' : { { { cDefs . O_RDWR } } } ,
302
- '"w"' : { { { cDefs . O_TRUNC } } } | { { { cDefs . O_CREAT } } } | { { { cDefs . O_WRONLY } } } ,
303
- '"w+"' : { { { cDefs . O_TRUNC } } } | { { { cDefs . O_CREAT } } } | { { { cDefs . O_RDWR } } } ,
304
- '"a"' : { { { cDefs . O_APPEND } } } | { { { cDefs . O_CREAT } } } | { { { cDefs . O_WRONLY } } } ,
305
- '"a+"' : { { { cDefs . O_APPEND } } } | { { { cDefs . O_CREAT } } } | { { { cDefs . O_RDWR } } } ,
306
- } ,
307
- // convert the 'r', 'r+', etc. to it's corresponding set of O_* flags
308
- modeStringToFlags : ( str ) => {
309
- var flags = FS . flagModes [ str ] ;
310
- if ( typeof flags == 'undefined' ) {
311
- throw new Error ( 'Unknown file open mode: ' + str ) ;
312
- }
313
- return flags ;
314
- } ,
315
300
// convert O_* bitmask to a string for nodePermissions
316
301
flagsToPermissionString : ( flag ) => {
317
302
var perms = [ 'r' , 'w' , 'rw' ] [ flag & 3 ] ;
@@ -1010,7 +995,7 @@ FS.staticInit();` +
1010
995
if ( path === "" ) {
1011
996
throw new FS . ErrnoError ( { { { cDefs . ENOENT } } } ) ;
1012
997
}
1013
- flags = typeof flags == 'string' ? FS . modeStringToFlags ( flags ) : flags ;
998
+ flags = typeof flags == 'string' ? FS_modeStringToFlags ( flags ) : flags ;
1014
999
mode = typeof mode == 'undefined' ? 438 /* 0666 */ : mode ;
1015
1000
if ( ( flags & { { { cDefs . O_CREAT } } } ) ) {
1016
1001
mode = ( mode & { { { cDefs . S_IALLUGO } } } ) | { { { cDefs . S_IFREG } } } ;
@@ -1536,12 +1521,6 @@ FS.staticInit();` +
1536
1521
//
1537
1522
// old v1 compatibility functions
1538
1523
//
1539
- getMode : ( canRead , canWrite ) = > {
1540
- var mode = 0 ;
1541
- if ( canRead ) mode |= { { { cDefs . S_IRUGO } } } | { { { cDefs . S_IXUGO } } } ;
1542
- if ( canWrite ) mode |= { { { cDefs . S_IWUGO } } } ;
1543
- return mode ;
1544
- } ,
1545
1524
findObject : ( path , dontResolveLastLink ) = > {
1546
1525
var ret = FS . analyzePath ( path , dontResolveLastLink ) ;
1547
1526
if ( ! ret . exists ) {
@@ -1595,7 +1574,7 @@ FS.staticInit();` +
1595
1574
} ,
1596
1575
createFile : ( parent , name , properties , canRead , canWrite ) => {
1597
1576
var path = PATH . join2 ( typeof parent == 'string' ? parent : FS . getPath ( parent ) , name ) ;
1598
- var mode = FS . getMode ( canRead , canWrite ) ;
1577
+ var mode = FS_getMode ( canRead , canWrite ) ;
1599
1578
return FS . create ( path , mode ) ;
1600
1579
} ,
1601
1580
createDataFile : ( parent , name , data , canRead , canWrite , canOwn ) = > {
@@ -1604,7 +1583,7 @@ FS.staticInit();` +
1604
1583
parent = typeof parent == 'string' ? parent : FS . getPath ( parent ) ;
1605
1584
path = name ? PATH . join2 ( parent , name ) : parent ;
1606
1585
}
1607
- var mode = FS . getMode ( canRead , canWrite ) ;
1586
+ var mode = FS_getMode ( canRead , canWrite ) ;
1608
1587
var node = FS . create ( path , mode ) ;
1609
1588
if ( data ) {
1610
1589
if ( typeof data == 'string' ) {
@@ -1623,7 +1602,7 @@ FS.staticInit();` +
1623
1602
} ,
1624
1603
createDevice : ( parent , name , input , output ) => {
1625
1604
var path = PATH . join2 ( typeof parent == 'string' ? parent : FS . getPath ( parent ) , name ) ;
1626
- var mode = FS . getMode ( ! ! input , ! ! output ) ;
1605
+ var mode = FS_getMode ( ! ! input , ! ! output ) ;
1627
1606
if ( ! FS . createDevice . major ) FS . createDevice . major = 64 ;
1628
1607
var dev = FS . makedev ( FS . createDevice . major ++ , 0 ) ;
1629
1608
// Create a fake device that a set of stream ops to emulate
@@ -1872,47 +1851,6 @@ FS.staticInit();` +
1872
1851
node . stream_ops = stream_ops ;
1873
1852
return node ;
1874
1853
} ,
1875
- // Preloads a file asynchronously. You can call this before run, for example in
1876
- // preRun. run will be delayed until this file arrives and is set up.
1877
- // If you call it after run(), you may want to pause the main loop until it
1878
- // completes, if so, you can use the onload parameter to be notified when
1879
- // that happens.
1880
- // In addition to normally creating the file, we also asynchronously preload
1881
- // the browser-friendly versions of it: For an image, we preload an Image
1882
- // element and for an audio, and Audio. These are necessary for SDL_Image
1883
- // and _Mixer to find the files in preloadedImages/Audios.
1884
- // You can also call this with a typed array instead of a url. It will then
1885
- // do preloading for the Image/Audio part, as if the typed array were the
1886
- // result of an XHR that you did manually.
1887
- createPreloadedFile : ( parent , name , url , canRead , canWrite , onload , onerror , dontCreateFile , canOwn , preFinish ) = > {
1888
- // TODO we should allow people to just pass in a complete filename instead
1889
- // of parent and name being that we just join them anyways
1890
- var fullname = name ? PATH_FS . resolve ( PATH . join2 ( parent , name ) ) : parent ;
1891
- var dep = getUniqueRunDependency ( 'cp ' + fullname ) ; // might have several active requests for the same fullname
1892
- function processData ( byteArray ) {
1893
- function finish ( byteArray ) {
1894
- if ( preFinish ) preFinish ( ) ;
1895
- if ( ! dontCreateFile ) {
1896
- FS . createDataFile ( parent , name , byteArray , canRead , canWrite , canOwn ) ;
1897
- }
1898
- if ( onload ) onload ( ) ;
1899
- removeRunDependency ( dep ) ;
1900
- }
1901
- if ( Browser . handledByPreloadPlugin ( byteArray , fullname , finish , ( ) => {
1902
- if ( onerror ) onerror ( ) ;
1903
- removeRunDependency ( dep ) ;
1904
- } ) ) {
1905
- return ;
1906
- }
1907
- finish ( byteArray ) ;
1908
- }
1909
- addRunDependency ( dep ) ;
1910
- if ( typeof url == 'string' ) {
1911
- asyncLoad ( url , ( byteArray ) => processData ( byteArray ) , onerror ) ;
1912
- } else {
1913
- processData ( url ) ;
1914
- }
1915
- } ,
1916
1854
1917
1855
// Removed v1 functions
1918
1856
#if ASSERTIONS
0 commit comments