parse.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. var tap = require("tap")
  2. , tar = require("../tar.js")
  3. , fs = require("fs")
  4. , path = require("path")
  5. , file = path.resolve(__dirname, "fixtures/c.tar")
  6. , index = 0
  7. , expect =
  8. [ [ 'entry',
  9. { path: 'c.txt',
  10. mode: 420,
  11. uid: 24561,
  12. gid: 20,
  13. size: 513,
  14. mtime: new Date('Wed, 26 Oct 2011 01:10:58 GMT'),
  15. cksum: 5422,
  16. type: '0',
  17. linkpath: '',
  18. ustar: 'ustar\0',
  19. ustarver: '00',
  20. uname: 'isaacs',
  21. gname: 'staff',
  22. devmaj: 0,
  23. devmin: 0,
  24. fill: '' },
  25. undefined ],
  26. [ 'entry',
  27. { path: 'cc.txt',
  28. mode: 420,
  29. uid: 24561,
  30. gid: 20,
  31. size: 513,
  32. mtime: new Date('Wed, 26 Oct 2011 01:11:02 GMT'),
  33. cksum: 5525,
  34. type: '0',
  35. linkpath: '',
  36. ustar: 'ustar\0',
  37. ustarver: '00',
  38. uname: 'isaacs',
  39. gname: 'staff',
  40. devmaj: 0,
  41. devmin: 0,
  42. fill: '' },
  43. undefined ],
  44. [ 'entry',
  45. { path: 'r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  46. mode: 420,
  47. uid: 24561,
  48. gid: 20,
  49. size: 100,
  50. mtime: new Date('Thu, 27 Oct 2011 03:43:23 GMT'),
  51. cksum: 18124,
  52. type: '0',
  53. linkpath: '',
  54. ustar: 'ustar\0',
  55. ustarver: '00',
  56. uname: 'isaacs',
  57. gname: 'staff',
  58. devmaj: 0,
  59. devmin: 0,
  60. fill: '' },
  61. undefined ],
  62. [ 'entry',
  63. { path: 'Ω.txt',
  64. mode: 420,
  65. uid: 24561,
  66. gid: 20,
  67. size: 2,
  68. mtime: new Date('Thu, 27 Oct 2011 17:51:49 GMT'),
  69. cksum: 5695,
  70. type: '0',
  71. linkpath: '',
  72. ustar: 'ustar\0',
  73. ustarver: '00',
  74. uname: 'isaacs',
  75. gname: 'staff',
  76. devmaj: 0,
  77. devmin: 0,
  78. fill: '' },
  79. undefined ],
  80. [ 'extendedHeader',
  81. { path: 'PaxHeader/Ω.txt',
  82. mode: 420,
  83. uid: 24561,
  84. gid: 20,
  85. size: 120,
  86. mtime: new Date('Thu, 27 Oct 2011 17:51:49 GMT'),
  87. cksum: 6702,
  88. type: 'x',
  89. linkpath: '',
  90. ustar: 'ustar\0',
  91. ustarver: '00',
  92. uname: 'isaacs',
  93. gname: 'staff',
  94. devmaj: 0,
  95. devmin: 0,
  96. fill: '' },
  97. { path: 'Ω.txt',
  98. ctime: 1319737909,
  99. atime: 1319739061,
  100. dev: 234881026,
  101. ino: 51693379,
  102. nlink: 1 } ],
  103. [ 'entry',
  104. { path: 'Ω.txt',
  105. mode: 420,
  106. uid: 24561,
  107. gid: 20,
  108. size: 2,
  109. mtime: new Date('Thu, 27 Oct 2011 17:51:49 GMT'),
  110. cksum: 5695,
  111. type: '0',
  112. linkpath: '',
  113. ustar: 'ustar\0',
  114. ustarver: '00',
  115. uname: 'isaacs',
  116. gname: 'staff',
  117. devmaj: 0,
  118. devmin: 0,
  119. fill: '',
  120. ctime: new Date('Thu, 27 Oct 2011 17:51:49 GMT'),
  121. atime: new Date('Thu, 27 Oct 2011 18:11:01 GMT'),
  122. dev: 234881026,
  123. ino: 51693379,
  124. nlink: 1 },
  125. undefined ],
  126. [ 'extendedHeader',
  127. { path: 'PaxHeader/200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  128. mode: 420,
  129. uid: 24561,
  130. gid: 20,
  131. size: 353,
  132. mtime: new Date('Thu, 27 Oct 2011 03:41:08 GMT'),
  133. cksum: 14488,
  134. type: 'x',
  135. linkpath: '',
  136. ustar: 'ustar\0',
  137. ustarver: '00',
  138. uname: 'isaacs',
  139. gname: 'staff',
  140. devmaj: 0,
  141. devmin: 0,
  142. fill: '' },
  143. { path: '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  144. ctime: 1319686868,
  145. atime: 1319741254,
  146. 'LIBARCHIVE.creationtime': '1319686852',
  147. dev: 234881026,
  148. ino: 51681874,
  149. nlink: 1 } ],
  150. [ 'entry',
  151. { path: '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  152. mode: 420,
  153. uid: 24561,
  154. gid: 20,
  155. size: 200,
  156. mtime: new Date('Thu, 27 Oct 2011 03:41:08 GMT'),
  157. cksum: 14570,
  158. type: '0',
  159. linkpath: '',
  160. ustar: 'ustar\0',
  161. ustarver: '00',
  162. uname: 'isaacs',
  163. gname: 'staff',
  164. devmaj: 0,
  165. devmin: 0,
  166. fill: '',
  167. ctime: new Date('Thu, 27 Oct 2011 03:41:08 GMT'),
  168. atime: new Date('Thu, 27 Oct 2011 18:47:34 GMT'),
  169. 'LIBARCHIVE.creationtime': '1319686852',
  170. dev: 234881026,
  171. ino: 51681874,
  172. nlink: 1 },
  173. undefined ],
  174. [ 'longPath',
  175. { path: '././@LongLink',
  176. mode: 0,
  177. uid: 0,
  178. gid: 0,
  179. size: 201,
  180. mtime: new Date('Thu, 01 Jan 1970 00:00:00 GMT'),
  181. cksum: 4976,
  182. type: 'L',
  183. linkpath: '',
  184. ustar: false },
  185. '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' ],
  186. [ 'entry',
  187. { path: '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  188. mode: 420,
  189. uid: 1000,
  190. gid: 1000,
  191. size: 201,
  192. mtime: new Date('Thu, 27 Oct 2011 22:21:50 GMT'),
  193. cksum: 14086,
  194. type: '0',
  195. linkpath: '',
  196. ustar: false },
  197. undefined ],
  198. [ 'longLinkpath',
  199. { path: '././@LongLink',
  200. mode: 0,
  201. uid: 0,
  202. gid: 0,
  203. size: 201,
  204. mtime: new Date('Thu, 01 Jan 1970 00:00:00 GMT'),
  205. cksum: 4975,
  206. type: 'K',
  207. linkpath: '',
  208. ustar: false },
  209. '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' ],
  210. [ 'longPath',
  211. { path: '././@LongLink',
  212. mode: 0,
  213. uid: 0,
  214. gid: 0,
  215. size: 201,
  216. mtime: new Date('Thu, 01 Jan 1970 00:00:00 GMT'),
  217. cksum: 4976,
  218. type: 'L',
  219. linkpath: '',
  220. ustar: false },
  221. '200LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL' ],
  222. [ 'entry',
  223. { path: '200LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL',
  224. mode: 511,
  225. uid: 1000,
  226. gid: 1000,
  227. size: 0,
  228. mtime: new Date('Fri, 28 Oct 2011 23:05:17 GMT'),
  229. cksum: 21603,
  230. type: '2',
  231. linkpath: '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  232. ustar: false },
  233. undefined ],
  234. [ 'extendedHeader',
  235. { path: 'PaxHeader/200-hard',
  236. mode: 420,
  237. uid: 24561,
  238. gid: 20,
  239. size: 143,
  240. mtime: new Date('Thu, 27 Oct 2011 03:41:08 GMT'),
  241. cksum: 6533,
  242. type: 'x',
  243. linkpath: '',
  244. ustar: 'ustar\0',
  245. ustarver: '00',
  246. uname: 'isaacs',
  247. gname: 'staff',
  248. devmaj: 0,
  249. devmin: 0,
  250. fill: '' },
  251. { ctime: 1320617144,
  252. atime: 1320617232,
  253. 'LIBARCHIVE.creationtime': '1319686852',
  254. dev: 234881026,
  255. ino: 51681874,
  256. nlink: 2 } ],
  257. [ 'entry',
  258. { path: '200-hard',
  259. mode: 420,
  260. uid: 24561,
  261. gid: 20,
  262. size: 200,
  263. mtime: new Date('Thu, 27 Oct 2011 03:41:08 GMT'),
  264. cksum: 5526,
  265. type: '0',
  266. linkpath: '',
  267. ustar: 'ustar\0',
  268. ustarver: '00',
  269. uname: 'isaacs',
  270. gname: 'staff',
  271. devmaj: 0,
  272. devmin: 0,
  273. fill: '',
  274. ctime: new Date('Sun, 06 Nov 2011 22:05:44 GMT'),
  275. atime: new Date('Sun, 06 Nov 2011 22:07:12 GMT'),
  276. 'LIBARCHIVE.creationtime': '1319686852',
  277. dev: 234881026,
  278. ino: 51681874,
  279. nlink: 2 },
  280. undefined ],
  281. [ 'extendedHeader',
  282. { path: 'PaxHeader/200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  283. mode: 420,
  284. uid: 24561,
  285. gid: 20,
  286. size: 353,
  287. mtime: new Date('Thu, 27 Oct 2011 03:41:08 GMT'),
  288. cksum: 14488,
  289. type: 'x',
  290. linkpath: '',
  291. ustar: 'ustar\0',
  292. ustarver: '00',
  293. uname: 'isaacs',
  294. gname: 'staff',
  295. devmaj: 0,
  296. devmin: 0,
  297. fill: '' },
  298. { path: '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  299. ctime: 1320617144,
  300. atime: 1320617406,
  301. 'LIBARCHIVE.creationtime': '1319686852',
  302. dev: 234881026,
  303. ino: 51681874,
  304. nlink: 2 } ],
  305. [ 'entry',
  306. { path: '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  307. mode: 420,
  308. uid: 24561,
  309. gid: 20,
  310. size: 0,
  311. mtime: new Date('Thu, 27 Oct 2011 03:41:08 GMT'),
  312. cksum: 15173,
  313. type: '1',
  314. linkpath: '200-hard',
  315. ustar: 'ustar\0',
  316. ustarver: '00',
  317. uname: 'isaacs',
  318. gname: 'staff',
  319. devmaj: 0,
  320. devmin: 0,
  321. fill: '',
  322. ctime: new Date('Sun, 06 Nov 2011 22:05:44 GMT'),
  323. atime: new Date('Sun, 06 Nov 2011 22:10:06 GMT'),
  324. 'LIBARCHIVE.creationtime': '1319686852',
  325. dev: 234881026,
  326. ino: 51681874,
  327. nlink: 2 },
  328. undefined ] ]
  329. tap.test("parser test", function (t) {
  330. var parser = tar.Parse()
  331. parser.on("end", function () {
  332. t.equal(index, expect.length, "saw all expected events")
  333. t.end()
  334. })
  335. fs.createReadStream(file)
  336. .pipe(parser)
  337. .on("*", function (ev, entry) {
  338. var wanted = expect[index]
  339. if (!wanted) {
  340. return t.fail("Unexpected event: " + ev)
  341. }
  342. var result = [ev, entry.props]
  343. entry.on("end", function () {
  344. result.push(entry.fields || entry.body)
  345. t.equal(ev, wanted[0], index + " event type")
  346. t.equivalent(entry.props, wanted[1], wanted[1].path + " entry properties")
  347. if (wanted[2]) {
  348. t.equivalent(result[2], wanted[2], "metadata values")
  349. }
  350. index ++
  351. })
  352. })
  353. })