fs.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. * Copyright 2012 The Closure Compiler Authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /**
  17. * @fileoverview Definitions for node's "fs" module.
  18. * @see http://nodejs.org/api/fs.html
  19. * @externs
  20. * @author Daniel Wirtz <dcode@dcode.io>
  21. */
  22. /**
  23. BEGIN_NODE_INCLUDE
  24. var fs = require('fs');
  25. END_NODE_INCLUDE
  26. */
  27. var fs = {};
  28. /**
  29. * @param {string} oldPath
  30. * @param {string} newPath
  31. * @param {function(...)=} callback
  32. */
  33. fs.rename = function(oldPath, newPath, callback) {};
  34. /**
  35. * @param {string} oldPath
  36. * @param {string} newPath
  37. */
  38. fs.renameSync = function(oldPath, newPath) {};
  39. /**
  40. * @param {*} fd
  41. * @param {number} len
  42. * @param {function(...)=} callback
  43. */
  44. fs.truncate = function(fd, len, callback) {};
  45. /**
  46. * @param {*} fd
  47. * @param {number} len
  48. */
  49. fs.truncateSync = function(fd, len) {};
  50. /**
  51. * @param {string} path
  52. * @param {number} uid
  53. * @param {number} gid
  54. * @param {function(...)=} callback
  55. */
  56. fs.chown = function(path, uid, gid, callback) {};
  57. /**
  58. * @param {string} path
  59. * @param {number} uid
  60. * @param {number} gid
  61. */
  62. fs.chownSync = function(path, uid, gid) {};
  63. /**
  64. * @param {*} fd
  65. * @param {number} uid
  66. * @param {number} gid
  67. * @param {function(...)=} callback
  68. */
  69. fs.fchown = function(fd, uid, gid, callback) {};
  70. /**
  71. * @param {*} fd
  72. * @param {number} uid
  73. * @param {number} gid
  74. */
  75. fs.fchownSync = function(fd, uid, gid) {};
  76. /**
  77. * @param {string} path
  78. * @param {number} uid
  79. * @param {number} gid
  80. * @param {function(...)=} callback
  81. */
  82. fs.lchown = function(path, uid, gid, callback) {};
  83. /**
  84. * @param {string} path
  85. * @param {number} uid
  86. * @param {number} gid
  87. */
  88. fs.lchownSync = function(path, uid, gid) {};
  89. /**
  90. * @param {string} path
  91. * @param {number} mode
  92. * @param {function(...)=} callback
  93. */
  94. fs.chmod = function(path, mode, callback) {};
  95. /**
  96. * @param {string} path
  97. * @param {number} mode
  98. */
  99. fs.chmodSync = function(path, mode) {};
  100. /**
  101. * @param {*} fd
  102. * @param {number} mode
  103. * @param {function(...)=} callback
  104. */
  105. fs.fchmod = function(fd, mode, callback) {};
  106. /**
  107. * @param {*} fd
  108. * @param {number} mode
  109. */
  110. fs.fchmodSync = function(fd, mode) {};
  111. /**
  112. * @param {string} path
  113. * @param {number} mode
  114. * @param {function(...)=} callback
  115. */
  116. fs.lchmod = function(path, mode, callback) {};
  117. /**
  118. * @param {string} path
  119. * @param {number} mode
  120. */
  121. fs.lchmodSync = function(path, mode) {};
  122. /**
  123. * @param {string} path
  124. * @param {function(string, fs.Stats)=} callback
  125. * @nosideeffects
  126. */
  127. fs.stat = function(path, callback) {};
  128. /**
  129. * @param {string} path
  130. * @return {fs.Stats}
  131. * @nosideeffects
  132. */
  133. fs.statSync = function(path) {}
  134. /**
  135. * @param {*} fd
  136. * @param {function(string, fs.Stats)=} callback
  137. * @nosideeffects
  138. */
  139. fs.fstat = function(fd, callback) {};
  140. /**
  141. * @param {*} fd
  142. * @return {fs.Stats}
  143. * @nosideeffects
  144. */
  145. fs.fstatSync = function(fd) {}
  146. /**
  147. * @param {string} path
  148. * @param {function(string, fs.Stats)=} callback
  149. * @nosideeffects
  150. */
  151. fs.lstat = function(path, callback) {};
  152. /**
  153. * @param {string} path
  154. * @return {fs.Stats}
  155. * @nosideeffects
  156. */
  157. fs.lstatSync = function(path) {}
  158. /**
  159. * @param {string} srcpath
  160. * @param {string} dstpath
  161. * @param {function(...)=} callback
  162. */
  163. fs.link = function(srcpath, dstpath, callback) {};
  164. /**
  165. * @param {string} srcpath
  166. * @param {string} dstpath
  167. */
  168. fs.linkSync = function(srcpath, dstpath) {};
  169. /**
  170. * @param {string} srcpath
  171. * @param {string} dstpath
  172. * @param {string=} type
  173. * @param {function(...)=} callback
  174. */
  175. fs.symlink = function(srcpath, dstpath, type, callback) {};
  176. /**
  177. * @param {string} srcpath
  178. * @param {string} dstpath
  179. * @param {string=} type
  180. */
  181. fs.symlinkSync = function(srcpath, dstpath, type) {};
  182. /**
  183. * @param {string} path
  184. * @param {function(string, string)=} callback
  185. * @nosideeffects
  186. */
  187. fs.readlink = function(path, callback) {};
  188. /**
  189. * @param {string} path
  190. * @return {string}
  191. * @nosideeffects
  192. */
  193. fs.readlinkSync = function(path) {};
  194. /**
  195. * @param {string} path
  196. * @param {object.<string,string>=|function(string, string)=} cache
  197. * @param {function(string, string)=} callback
  198. * @nosideeffects
  199. */
  200. fs.realpath = function(path, cache, callback) {};
  201. /**
  202. * @param {string} path
  203. * @param {object.<string,string>=} cache
  204. * @return {string}
  205. * @nosideeffects
  206. */
  207. fs.realpathSync = function(path, cache) {};
  208. /**
  209. * @param {string} path
  210. * @param {function(...)=} callback
  211. */
  212. fs.unlink = function(path, callback) {};
  213. /**
  214. * @param {string} path
  215. */
  216. fs.unlinkSync = function(path) {};
  217. /**
  218. * @param {string} path
  219. * @param {function(...)=} callback
  220. */
  221. fs.rmdir = function(path, callback) {};
  222. /**
  223. * @param {string} path
  224. */
  225. fs.rmdirSync = function(path) {};
  226. /**
  227. * @param {string} path
  228. * @param {number=} mode
  229. * @param {function(...)=} callback
  230. */
  231. fs.mkdir = function(path, mode, callback) {};
  232. /**
  233. * @param {string} path
  234. * @param {number=} mode
  235. */
  236. fs.mkdirSync = function(path, mode) {};
  237. /**
  238. * @param {string} path
  239. * @param {function(string,array.<string>)=} callback
  240. * @nosideeffects
  241. */
  242. fs.readdir = function(path, callback) {};
  243. /**
  244. * @param {string} path
  245. * @return {array.<string>}
  246. * @nosideeffects
  247. */
  248. fs.readdirSync = function(path) {};
  249. /**
  250. * @param {*} fd
  251. * @param {function(...)=} callback
  252. */
  253. fs.close = function(fd, callback) {};
  254. /**
  255. * @param {*} fd
  256. */
  257. fs.closeSync = function(fd) {};
  258. /**
  259. * @param {string} path
  260. * @param {string} flags
  261. * @param {number=} mode
  262. * @param {function(string, *)=} callback
  263. * @nosideeffects
  264. */
  265. fs.open = function(path, flags, mode, callback) {};
  266. /**
  267. * @param {string} path
  268. * @param {string} flags
  269. * @param {number=} mode
  270. * @return {*}
  271. * @nosideeffects
  272. */
  273. fs.openSync = function(path, flags, mode) {};
  274. /**
  275. * @param {string} path
  276. * @param {number} atime
  277. * @param {number} mtime
  278. * @param {function(...)=} callback
  279. * @nosideeffects
  280. */
  281. fs.utimes = function(path, atime, mtime, callback) {};
  282. /**
  283. * @param {string} path
  284. * @param {number} atime
  285. * @param {number} mtime
  286. * @nosideeffects
  287. */
  288. fs.utimesSync = function(path, atime, mtime) {};
  289. /**
  290. * @param {*} fd
  291. * @param {number} atime
  292. * @param {number} mtime
  293. * @param {function(...)=} callback
  294. * @nosideeffects
  295. */
  296. fs.futimes = function(fd, atime, mtime, callback) {};
  297. /**
  298. * @param {*} fd
  299. * @param {number} atime
  300. * @param {number} mtime
  301. * @nosideeffects
  302. */
  303. fs.futimesSync = function(fd, atime, mtime) {};
  304. /**
  305. * @param {*} fd
  306. * @param {function(...)=} callback
  307. */
  308. fs.fsync = function(fd, callback) {};
  309. /**
  310. * @param {*} fd
  311. */
  312. fs.fsyncSync = function(fd) {};
  313. /**
  314. * @param {*} fd
  315. * @param {*} buffer
  316. * @param {number} offset
  317. * @param {number} length
  318. * @param {number} position
  319. * @param {function(string, number, *)=} callback
  320. */
  321. fs.write = function(fd, buffer, offset, length, position, callback) {};
  322. /**
  323. * @param {*} fd
  324. * @param {*} buffer
  325. * @param {number} offset
  326. * @param {number} length
  327. * @param {number} position
  328. * @return {number}
  329. */
  330. fs.writeSync = function(fd, buffer, offset, length, position) {};
  331. /**
  332. * @param {*} fd
  333. * @param {*} buffer
  334. * @param {number} offset
  335. * @param {number} length
  336. * @param {number} position
  337. * @param {function(string, number, *)=} callback
  338. * @nosideeffects
  339. */
  340. fs.read = function(fd, buffer, offset, length, position, callback) {};
  341. /**
  342. * @param {*} fd
  343. * @param {*} buffer
  344. * @param {number} offset
  345. * @param {number} length
  346. * @param {number} position
  347. * @return {number}
  348. * @nosideeffects
  349. */
  350. fs.readSync = function(fd, buffer, offset, length, position) {};
  351. /**
  352. * @param {string} filename
  353. * @param {string=|function(string, *)=}encoding
  354. * @param {function(string, *)=} callback
  355. * @nosideeffects
  356. */
  357. fs.readFile = function(filename, encoding, callback) {};
  358. /**
  359. * @param {string} filename
  360. * @param {string=} encoding
  361. * @nosideeffects
  362. */
  363. fs.readFileSync = function(filename, encoding) {};
  364. /**
  365. * @param {string} filename
  366. * @param {*} data
  367. * @param {string=|function(string)=} encoding
  368. * @param {function(string)=} callback
  369. */
  370. fs.writeFile = function(filename, data, encoding, callback) {};
  371. /**
  372. * @param {string} filename
  373. * @param {*} data
  374. * @param {string=} encoding
  375. */
  376. fs.writeFileSync = function(filename, data, encoding) {};
  377. /**
  378. * @param {string} filename
  379. * @param {*} data
  380. * @param {string=|function(string)=} encoding
  381. * @param {function(string)=} callback
  382. */
  383. fs.appendFile = function(filename, data, encoding, callback) {};
  384. /**
  385. * @param {string} filename
  386. * @param {*} data
  387. * @param {string=|function(string)=} encoding
  388. */
  389. fs.appendFileSync = function(filename, data, encoding) {};
  390. /**
  391. * @param {string} filename
  392. * @param {{persistent: boolean, interval: number}=|function(*,*)} options
  393. * @param {function(*,*)=} listener
  394. */
  395. fs.watchFile = function(filename, options, listener) {};
  396. /**
  397. * @param {string} filename
  398. * @param {function=} listener
  399. */
  400. fs.unwatchFile = function(filename, listener) {};
  401. /**
  402. *
  403. * @param {string} filename
  404. * @param {{persistent: boolean}=|function(string, string)} options
  405. * @param {function(string, string)=} listener
  406. * @return {fs.FSWatcher}
  407. */
  408. fs.watch = function(filename, options, listener) {};
  409. /**
  410. * @param {string} path
  411. * @param {function(boolean)} callback
  412. * @nosideeffects
  413. */
  414. fs.exists = function(path, callback) {};
  415. /**
  416. * @param {string} path
  417. * @nosideeffects
  418. */
  419. fs.existsSync = function(path) {};
  420. /**
  421. * @constructor
  422. */
  423. fs.Stats = function() {};
  424. /**
  425. * @return {boolean}
  426. * @nosideeffects
  427. */
  428. fs.Stats.prototype.isFile = function() {};
  429. /**
  430. * @return {boolean}
  431. * @nosideeffects
  432. */
  433. fs.Stats.prototype.isDirectory = function() {};
  434. /**
  435. * @return {boolean}
  436. * @nosideeffects
  437. */
  438. fs.Stats.prototype.isBlockDevice = function() {};
  439. /**
  440. * @return {boolean}
  441. * @nosideeffects
  442. */
  443. fs.Stats.prototype.isCharacterDevice = function() {};
  444. /**
  445. * @return {boolean}
  446. * @nosideeffects
  447. */
  448. fs.Stats.prototype.isSymbolicLink = function() {};
  449. /**
  450. * @return {boolean}
  451. * @nosideeffects
  452. */
  453. fs.Stats.prototype.isFIFO = function() {};
  454. /**
  455. * @return {boolean}
  456. * @nosideeffects
  457. */
  458. fs.Stats.prototype.isSocket = function() {};
  459. /**
  460. * @type {number}
  461. */
  462. fs.Stats.prototype.dev = 0;
  463. /**
  464. * @type {number}
  465. */
  466. fs.Stats.prototype.ino = 0;
  467. /**
  468. * @type {number}
  469. */
  470. fs.Stats.prototype.mode = 0;
  471. /**
  472. * @type {number}
  473. */
  474. fs.Stats.prototype.nlink = 0;
  475. /**
  476. * @type {number}
  477. */
  478. fs.Stats.prototype.uid = 0;
  479. /**
  480. * @type {number}
  481. */
  482. fs.Stats.prototype.gid = 0;
  483. /**
  484. * @type {number}
  485. */
  486. fs.Stats.prototype.rdev = 0;
  487. /**
  488. * @type {number}
  489. */
  490. fs.Stats.prototype.size = 0;
  491. /**
  492. * @type {number}
  493. */
  494. fs.Stats.prototype.blkSize = 0;
  495. /**
  496. * @type {number}
  497. */
  498. fs.Stats.prototype.blocks = 0;
  499. /**
  500. * @type {Date}
  501. */
  502. fs.Stats.prototype.atime = 0;
  503. /**
  504. * @type {Date}
  505. */
  506. fs.Stats.prototype.mtime = 0;
  507. /**
  508. * @type {Date}
  509. */
  510. fs.Stats.prototype.ctime = 0;
  511. /**
  512. * @param {string} path
  513. * @param {{flags: string, encoding: ?string, fd: *, mode: number, bufferSize: number}=} options
  514. * @nosideeffects
  515. */
  516. fs.createReadStream = function(path, options) {};
  517. /**
  518. * @constructor
  519. * @extends {stream.ReadableStream}
  520. */
  521. fs.ReadStream = function() {};
  522. /**
  523. * @param {string} path
  524. * @param {{flags: string, encoding: ?string, mode: number}=} options
  525. * @nosideeffects
  526. */
  527. fs.createWriteStream = function(path, options) {};
  528. /**
  529. * @constructor
  530. * @extends {stream.WritableStream}
  531. */
  532. fs.WriteStream = function() {};
  533. /**
  534. * @param {string} event
  535. * @param {function(...)} callback
  536. */
  537. fs.WriteStream.prototype.on = function(event, callback) {};
  538. /**
  539. * @constructor
  540. */
  541. fs.FSWatcher = function() {};
  542. /**
  543. */
  544. fs.FSWatcher.prototype.close = function() {};
  545. /**
  546. * @param {string} event
  547. * @param {function(...)} callback
  548. */
  549. fs.FSWatcher.prototype.on = function(event, callback) {};