@@ -315,21 +315,21 @@ checks to be performed. The following constants define the possible values of
315
315
` mode ` . It is possible to create a mask consisting of the bitwise OR of two or
316
316
more values.
317
317
318
- - ` fs.F_OK ` - ` path ` is visible to the calling process. This is useful
318
+ - ` fs.constants. F_OK ` - ` path ` is visible to the calling process. This is useful
319
319
for determining if a file exists, but says nothing about ` rwx ` permissions.
320
320
Default if no ` mode ` is specified.
321
- - ` fs.R_OK ` - ` path ` can be read by the calling process.
322
- - ` fs.W_OK ` - ` path ` can be written by the calling process.
323
- - ` fs.X_OK ` - ` path ` can be executed by the calling process. This has
324
- no effect on Windows (will behave like ` fs.F_OK ` ).
321
+ - ` fs.constants. R_OK ` - ` path ` can be read by the calling process.
322
+ - ` fs.constants. W_OK ` - ` path ` can be written by the calling process.
323
+ - ` fs.constants. X_OK ` - ` path ` can be executed by the calling process. This has
324
+ no effect on Windows (will behave like ` fs.constants. F_OK ` ).
325
325
326
326
The final argument, ` callback ` , is a callback function that is invoked with
327
327
a possible error argument. If any of the accessibility checks fail, the error
328
328
argument will be populated. The following example checks if the file
329
329
` /etc/passwd ` can be read and written by the current process.
330
330
331
331
``` js
332
- fs .access (' /etc/passwd' , fs .R_OK | fs .W_OK , (err ) => {
332
+ fs .access (' /etc/passwd' , fs .constants . R_OK | fs . constants .W_OK , (err ) => {
333
333
console .log (err ? ' no access!' : ' can read/write' );
334
334
});
335
335
```
@@ -342,8 +342,8 @@ added: v0.11.15
342
342
* ` path ` {String | Buffer}
343
343
* ` mode ` {Integer}
344
344
345
- Synchronous version of [ ` fs.access() ` ] [ ] . This throws if any accessibility checks
346
- fail, and does nothing otherwise.
345
+ Synchronous version of [ ` fs.access() ` ] [ ] . This throws if any accessibility
346
+ checks fail, and does nothing otherwise.
347
347
348
348
## fs.appendFile(file, data[ , options] , callback)
349
349
<!-- YAML
@@ -460,6 +460,12 @@ added: v0.1.21
460
460
461
461
Synchronous close(2). Returns ` undefined ` .
462
462
463
+ ## fs.constants
464
+
465
+ Returns an object containing commonly used constants for file system
466
+ operations. The specific constants currently defined are described in
467
+ [ FS Constants] [ ] .
468
+
463
469
## fs.createReadStream(path[ , options] )
464
470
<!-- YAML
465
471
added: v0.1.31
@@ -498,9 +504,9 @@ the file instead of the entire file. Both `start` and `end` are inclusive and
498
504
start at 0. The ` encoding ` can be any one of those accepted by [ ` Buffer ` ] [ ] .
499
505
500
506
If ` fd ` is specified, ` ReadStream ` will ignore the ` path ` argument and will use
501
- the specified file descriptor. This means that no ` 'open' ` event will be emitted.
502
- Note that ` fd ` should be blocking; non-blocking ` fd ` s should be passed to
503
- [ ` net.Socket ` ] [ ] .
507
+ the specified file descriptor. This means that no ` 'open' ` event will be
508
+ emitted. Note that ` fd ` should be blocking; non-blocking ` fd ` s should be passed
509
+ to [ ` net.Socket ` ] [ ] .
504
510
505
511
If ` autoClose ` is false, then the file descriptor won't be closed, even if
506
512
there's an error. It is your responsibility to close it and make sure
@@ -550,7 +556,8 @@ Returns a new [`WriteStream`][] object. (See [Writable Stream][]).
550
556
` options ` may also include a ` start ` option to allow writing data at
551
557
some position past the beginning of the file. Modifying a file rather
552
558
than replacing it may require a ` flags ` mode of ` r+ ` rather than the
553
- default mode ` w ` . The ` defaultEncoding ` can be any one of those accepted by [ ` Buffer ` ] [ ] .
559
+ default mode ` w ` . The ` defaultEncoding ` can be any one of those accepted by
560
+ [ ` Buffer ` ] [ ] .
554
561
555
562
If ` autoClose ` is set to true (default behavior) on ` error ` or ` end `
556
563
the file descriptor will be closed automatically. If ` autoClose ` is false,
@@ -597,7 +604,8 @@ added: v0.1.21
597
604
deprecated: v1.0.0
598
605
-->
599
606
600
- Stability: 0 - Deprecated: Use [`fs.statSync()`][] or [`fs.accessSync()`][] instead.
607
+ Stability: 0 - Deprecated: Use [`fs.statSync()`][] or [`fs.accessSync()`][]
608
+ instead.
601
609
602
610
* ` path ` {String | Buffer}
603
611
@@ -991,7 +999,7 @@ to a non-existent file. The exclusive flag may or may not work with network file
991
999
systems.
992
1000
993
1001
` flags ` can also be a number as documented by open(2); commonly used constants
994
- are available from ` require(' constants') ` . On Windows, flags are translated to
1002
+ are available from ` fs. constants` . On Windows, flags are translated to
995
1003
their equivalent ones where applicable, e.g. ` O_WRONLY ` to ` FILE_GENERIC_WRITE ` ,
996
1004
or ` O_EXCL|O_CREAT ` to ` CREATE_NEW ` , as accepted by CreateFileW.
997
1005
@@ -1294,11 +1302,11 @@ added: v0.1.31
1294
1302
* ` callback ` {Function}
1295
1303
1296
1304
Asynchronous symlink(2). No arguments other than a possible exception are given
1297
- to the completion callback.
1298
- The ` type ` argument can be set to ` 'dir' ` , ` ' file'` , or ` 'junction' ` (default
1299
- is ` 'file' ` ) and is only available on Windows (ignored on other platforms).
1300
- Note that Windows junction points require the destination path to be absolute. When using
1301
- ` 'junction' ` , the ` target ` argument will automatically be normalized to absolute path.
1305
+ to the completion callback. The ` type ` argument can be set to ` 'dir' ` ,
1306
+ ` ' file'` , or ` 'junction' ` (default is ` 'file' ` ) and is only available on
1307
+ Windows (ignored on other platforms). Note that Windows junction points require
1308
+ the destination path to be absolute. When using ` 'junction' ` , the ` target `
1309
+ argument will automatically be normalized to absolute path.
1302
1310
1303
1311
Here is an example below:
1304
1312
@@ -1543,9 +1551,9 @@ _Note: when an `fs.watchFile` operation results in an `ENOENT` error, it will
1543
1551
of zero. If the file is created later on, the listener will be called again,
1544
1552
with the latest stat objects. This is a change in functionality since v0.10._
1545
1553
1546
- _ Note: [ ` fs.watch() ` ] [ ] is more efficient than ` fs.watchFile ` and ` fs.unwatchFile ` .
1547
- ` fs.watch ` should be used instead of ` fs.watchFile ` and ` fs.unwatchFile `
1548
- when possible._
1554
+ _ Note: [ ` fs.watch() ` ] [ ] is more efficient than ` fs.watchFile ` and
1555
+ ` fs.unwatchFile ` . ` fs. watch` should be used instead of ` fs.watchFile ` and
1556
+ ` fs.unwatchFile ` when possible._
1549
1557
1550
1558
## fs.write(fd, buffer, offset, length[ , position] , callback)
1551
1559
<!-- YAML
@@ -1693,6 +1701,226 @@ added: v0.11.5
1693
1701
1694
1702
Synchronous versions of [ ` fs.write() ` ] [ ] . Returns the number of bytes written.
1695
1703
1704
+ ## FS Constants
1705
+
1706
+ The following constants are exported by ` fs.constants ` . ** Note:** Not every
1707
+ constant will be available on every operating system.
1708
+
1709
+ ### File Access Constants
1710
+
1711
+ The following constants are meant for use with [ ` fs.access() ` ] [ ] .
1712
+
1713
+ <table >
1714
+ <tr >
1715
+ <th>Constant</th>
1716
+ <th>Description</th>
1717
+ </tr >
1718
+ <tr >
1719
+ <td><code>F_OK</code></td>
1720
+ <td>Flag indicating that the file is visible to the calling process.</td>
1721
+ </tr >
1722
+ <tr >
1723
+ <td><code>R_OK</code></td>
1724
+ <td>Flag indicating that the file can be read by the calling process.</td>
1725
+ </tr >
1726
+ <tr >
1727
+ <td><code>W_OK</code></td>
1728
+ <td>Flag indicating that the file can be written by the calling
1729
+ process.</td>
1730
+ </tr >
1731
+ <tr >
1732
+ <td><code>X_OK</code></td>
1733
+ <td>Flag indicating that the file can be executed by the calling
1734
+ process.</td>
1735
+ </tr >
1736
+ </table >
1737
+
1738
+ ### File Open Constants
1739
+
1740
+ The following constants are meant for use with ` fs.open() ` .
1741
+
1742
+ <table >
1743
+ <tr >
1744
+ <th>Constant</th>
1745
+ <th>Description</th>
1746
+ </tr >
1747
+ <tr >
1748
+ <td><code>O_RDONLY</code></td>
1749
+ <td>Flag indicating to open a file for read-only access.</td>
1750
+ </tr >
1751
+ <tr >
1752
+ <td><code>O_WRONLY</code></td>
1753
+ <td>Flag indicating to open a file for write-only access.</td>
1754
+ </tr >
1755
+ <tr >
1756
+ <td><code>O_RDWR</code></td>
1757
+ <td>Flag indicating to open a file for read-write access.</td>
1758
+ </tr >
1759
+ <tr >
1760
+ <td><code>O_CREAT</code></td>
1761
+ <td>Flag indicating to create the file if it does not already exist.</td>
1762
+ </tr >
1763
+ <tr >
1764
+ <td><code>O_EXCL</code></td>
1765
+ <td>Flag indicating that opening a file should fail if the
1766
+ <code>O_CREAT</code> flag is set and the file already exists.</td>
1767
+ </tr >
1768
+ <tr >
1769
+ <td><code>O_NOCTTY</code></td>
1770
+ <td>Flag indicating that if path identifies a terminal device, opening the
1771
+ path shall not cause that terminal to become the controlling terminal for
1772
+ the process (if the process does not already have one).</td>
1773
+ </tr >
1774
+ <tr >
1775
+ <td><code>O_TRUNC</code></td>
1776
+ <td>Flag indicating that if the file exists and is a regular file, and the
1777
+ file is opened successfully for write access, its length shall be truncated
1778
+ to zero.</td>
1779
+ </tr >
1780
+ <tr >
1781
+ <td><code>O_APPEND</code></td>
1782
+ <td>Flag indicating that data will be appended to the end of the file.</td>
1783
+ </tr >
1784
+ <tr >
1785
+ <td><code>O_DIRECTORY</code></td>
1786
+ <td>Flag indicating that the open should fail if the path is not a
1787
+ directory.</td>
1788
+ </tr >
1789
+ <tr >
1790
+ <td ><code >O_NOATIME</code ></td >
1791
+ <td>Flag indicating reading accesses to the file system will no longer
1792
+ result in an update to the `atime` information associated with the file.
1793
+ This flag is available on Linux operating systems only.</td>
1794
+ </tr >
1795
+ <tr >
1796
+ <td><code>O_NOFOLLOW</code></td>
1797
+ <td>Flag indicating that the open should fail if the path is a symbolic
1798
+ link.</td>
1799
+ </tr >
1800
+ <tr >
1801
+ <td><code>O_SYNC</code></td>
1802
+ <td>Flag indicating that the file is opened for synchronous I/O.</td>
1803
+ </tr >
1804
+ <tr >
1805
+ <td><code>O_SYMLINK</code></td>
1806
+ <td>Flag indicating to open the symbolic link itself rather than the
1807
+ resource it is pointing to.</td>
1808
+ </tr >
1809
+ <tr >
1810
+ <td><code>O_DIRECT</code></td>
1811
+ <td>When set, an attempt will be made to minimize caching effects of file
1812
+ I/O.</td>
1813
+ </tr >
1814
+ <tr >
1815
+ <td><code>O_NONBLOCK</code></td>
1816
+ <td>Flag indicating to open the file in nonblocking mode when possible.</td>
1817
+ </tr >
1818
+ </table >
1819
+
1820
+ ### File Type Constants
1821
+
1822
+ The following constants are meant for use with the [ ` fs.Stats ` ] [ ] object's
1823
+ ` mode ` property for determining a file's type.
1824
+
1825
+ <table >
1826
+ <tr >
1827
+ <th>Constant</th>
1828
+ <th>Description</th>
1829
+ </tr >
1830
+ <tr >
1831
+ <td><code>S_IFMT</code></td>
1832
+ <td>Bit mask used to extract the file type code.</td>
1833
+ </tr >
1834
+ <tr >
1835
+ <td><code>S_IFREG</code></td>
1836
+ <td>File type constant for a regular file.</td>
1837
+ </tr >
1838
+ <tr >
1839
+ <td><code>S_IFDIR</code></td>
1840
+ <td>File type constant for a directory.</td>
1841
+ </tr >
1842
+ <tr >
1843
+ <td><code>S_IFCHR</code></td>
1844
+ <td>File type constant for a character-oriented device file.</td>
1845
+ </tr >
1846
+ <tr >
1847
+ <td><code>S_IFBLK</code></td>
1848
+ <td>File type constant for a block-oriented device file.</td>
1849
+ </tr >
1850
+ <tr >
1851
+ <td><code>S_IFIFO</code></td>
1852
+ <td>File type constant for a FIFO/pipe.</td>
1853
+ </tr >
1854
+ <tr >
1855
+ <td><code>S_IFLNK</code></td>
1856
+ <td>File type constant for a symbolic link.</td>
1857
+ </tr >
1858
+ <tr >
1859
+ <td><code>S_IFSOCK</code></td>
1860
+ <td>File type constant for a socket.</td>
1861
+ </tr >
1862
+ </table >
1863
+
1864
+ ### File Mode Constants
1865
+
1866
+ The following constants are meant for use with the [ ` fs.Stats ` ] [ ] object's
1867
+ ` mode ` property for determining the access permissions for a file.
1868
+
1869
+ <table >
1870
+ <tr >
1871
+ <th>Constant</th>
1872
+ <th>Description</th>
1873
+ </tr >
1874
+ <tr >
1875
+ <td><code>S_IRWXU</code></td>
1876
+ <td>File mode indicating readable, writable and executable by owner.</td>
1877
+ </tr >
1878
+ <tr >
1879
+ <td><code>S_IRUSR</code></td>
1880
+ <td>File mode indicating readable by owner.</td>
1881
+ </tr >
1882
+ <tr >
1883
+ <td><code>S_IWUSR</code></td>
1884
+ <td>File mode indicating writable by owner.</td>
1885
+ </tr >
1886
+ <tr >
1887
+ <td><code>S_IXUSR</code></td>
1888
+ <td>File mode indicating executable by owner.</td>
1889
+ </tr >
1890
+ <tr >
1891
+ <td><code>S_IRWXG</code></td>
1892
+ <td>File mode indicating readable, writable and executable by group.</td>
1893
+ </tr >
1894
+ <tr >
1895
+ <td><code>S_IRGRP</code></td>
1896
+ <td>File mode indicating readable by group.</td>
1897
+ </tr >
1898
+ <tr >
1899
+ <td><code>S_IWGRP</code></td>
1900
+ <td>File mode indicating writable by group.</td>
1901
+ </tr >
1902
+ <tr >
1903
+ <td><code>S_IXGRP</code></td>
1904
+ <td>File mode indicating executable by group.</td>
1905
+ </tr >
1906
+ <tr >
1907
+ <td><code>S_IRWXO</code></td>
1908
+ <td>File mode indicating readable, writable and executable by others.</td>
1909
+ </tr >
1910
+ <tr >
1911
+ <td><code>S_IROTH</code></td>
1912
+ <td>File mode indicating readable by others.</td>
1913
+ </tr >
1914
+ <tr >
1915
+ <td><code>S_IWOTH</code></td>
1916
+ <td>File mode indicating writable by others.</td>
1917
+ </tr >
1918
+ <tr >
1919
+ <td><code>S_IXOTH</code></td>
1920
+ <td>File mode indicating executable by others.</td>
1921
+ </tr >
1922
+ </table >
1923
+
1696
1924
[ `Buffer.byteLength` ] : buffer.html#buffer_class_method_buffer_bytelength_string_encoding
1697
1925
[ `Buffer` ] : buffer.html#buffer_buffer
1698
1926
[ Caveats ] : #fs_caveats
@@ -1726,9 +1954,12 @@ Synchronous versions of [`fs.write()`][]. Returns the number of bytes written.
1726
1954
[ Writable Stream ] : stream.html#stream_class_stream_writable
1727
1955
[ inode ] : http://www.linux.org/threads/intro-to-inodes.4130
1728
1956
[ FS Constants ] : #fs_fs_constants
1957
+ <<<<<<< HEAD
1729
1958
[ `inotify` ] : http://man7.org/linux/man-pages/man7/inotify.7.html
1730
1959
[ `kqueue` ] : https://www.freebsd.org/cgi/man.cgi?kqueue
1731
1960
[ `FSEvents` ] : https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/FSEvents_ProgGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40005289-CH1-SW1
1732
1961
[ `event ports` ] : http://illumos.org/man/port_create
1733
1962
[ `ReadDirectoryChangesW` ] : https://msdn.microsoft.com/en-us/library/windows/desktop/aa365465%28v=vs.85%29.aspx
1734
1963
[ `AHAFS` ] : https://www.ibm.com/developerworks/aix/library/au-aix_event_infrastructure/
1964
+ =======
1965
+ >>>>>>> dcccbfd... src: refactor require('constants')
0 commit comments