Skip to content

Commit 6bb11b8

Browse files
Hussein NasserHussein Nasser
authored andcommitted
bypass cache
1 parent 63de926 commit 6bb11b8

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

14-file-io/144-file-bypasscache.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const fs = require("fs");
2+
const p = '/Users/HusseinNasser/Desktop/udemy/os-course/Edited/01-Welcome.mp4'
3+
const fd = fs.openSync(p, 'rs+')//by pass file system cache
4+
console.log("file descriptor " + fd)
5+
fs.closeSync(fd);
6+
7+
/*
8+
The following flags are available wherever the flag option takes a string.
9+
10+
'a': Open file for appending. The file is created if it does not exist.
11+
12+
'ax': Like 'a' but fails if the path exists.
13+
14+
'a+': Open file for reading and appending. The file is created if it does not exist.
15+
16+
'ax+': Like 'a+' but fails if the path exists.
17+
18+
'as': Open file for appending in synchronous mode. The file is created if it does not exist.
19+
20+
'as+': Open file for reading and appending in synchronous mode. The file is created if it does not exist.
21+
22+
'r': Open file for reading. An exception occurs if the file does not exist.
23+
24+
'rs': Open file for reading in synchronous mode. An exception occurs if the file does not exist.
25+
26+
'r+': Open file for reading and writing. An exception occurs if the file does not exist.
27+
28+
'rs+': Open file for reading and writing in synchronous mode. Instructs the operating system to bypass the local file system cache.
29+
30+
This is primarily useful for opening files on NFS mounts as it allows skipping the potentially stale local cache. It has a very real impact on I/O performance so using this flag is not recommended unless it is needed.
31+
32+
This doesn't turn fs.open() or fsPromises.open() into a synchronous blocking call. If synchronous operation is desired, something like fs.openSync() should be used.
33+
34+
'w': Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
35+
36+
'wx': Like 'w' but fails if the path exists.
37+
38+
'w+': Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
39+
40+
'wx+': Like 'w+' but fails if the path exists.
41+
*/

0 commit comments

Comments
 (0)