pack.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  1. // the symlink file is excluded from git, because it makes
  2. // windows freak the hell out.
  3. var fs = require("fs")
  4. , path = require("path")
  5. , symlink = path.resolve(__dirname, "fixtures/symlink")
  6. try { fs.unlinkSync(symlink) } catch (e) {}
  7. fs.symlinkSync("./hardlink-1", symlink)
  8. process.on("exit", function () {
  9. fs.unlinkSync(symlink)
  10. })
  11. var tap = require("tap")
  12. , tar = require("../tar.js")
  13. , pkg = require("../package.json")
  14. , Pack = tar.Pack
  15. , fstream = require("fstream")
  16. , Reader = fstream.Reader
  17. , Writer = fstream.Writer
  18. , input = path.resolve(__dirname, "fixtures/")
  19. , target = path.resolve(__dirname, "tmp/pack.tar")
  20. , uid = process.getuid ? process.getuid() : 0
  21. , gid = process.getgid ? process.getgid() : 0
  22. , entries =
  23. // the global header and root fixtures/ dir are going to get
  24. // a different date each time, so omit that bit.
  25. // Also, dev/ino values differ across machines, so that's not
  26. // included.
  27. [ [ 'globalExtendedHeader',
  28. { path: 'PaxHeader/',
  29. mode: 438,
  30. uid: 0,
  31. gid: 0,
  32. type: 'g',
  33. linkpath: '',
  34. ustar: 'ustar\u0000',
  35. ustarver: '00',
  36. uname: '',
  37. gname: '',
  38. devmaj: 0,
  39. devmin: 0,
  40. fill: '' },
  41. { "NODETAR.author": pkg.author,
  42. "NODETAR.name": pkg.name,
  43. "NODETAR.description": pkg.description,
  44. "NODETAR.version": pkg.version,
  45. "NODETAR.repository.type": pkg.repository.type,
  46. "NODETAR.repository.url": pkg.repository.url,
  47. "NODETAR.main": pkg.main,
  48. "NODETAR.scripts.test": pkg.scripts.test } ]
  49. , [ 'entry',
  50. { path: 'fixtures/',
  51. mode: 493,
  52. uid: uid,
  53. gid: gid,
  54. size: 0,
  55. type: '5',
  56. linkpath: '',
  57. ustar: 'ustar\u0000',
  58. ustarver: '00',
  59. uname: '',
  60. gname: '',
  61. devmaj: 0,
  62. devmin: 0,
  63. fill: '' } ]
  64. , [ 'extendedHeader',
  65. { path: 'PaxHeader/fixtures/200cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  66. mode: 420,
  67. uid: uid,
  68. gid: gid,
  69. type: 'x',
  70. linkpath: '',
  71. ustar: 'ustar\u0000',
  72. ustarver: '00',
  73. uname: '',
  74. gname: '',
  75. devmaj: 0,
  76. devmin: 0,
  77. fill: '' },
  78. { path: 'fixtures/200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  79. 'NODETAR.depth': '1',
  80. 'NODETAR.type': 'File',
  81. nlink: 1,
  82. uid: uid,
  83. gid: gid,
  84. size: 200,
  85. 'NODETAR.blksize': '4096',
  86. 'NODETAR.blocks': '8' } ]
  87. , [ 'entry',
  88. { path: 'fixtures/200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  89. mode: 420,
  90. uid: uid,
  91. gid: gid,
  92. size: 200,
  93. type: '0',
  94. linkpath: '',
  95. ustar: 'ustar\u0000',
  96. ustarver: '00',
  97. uname: '',
  98. gname: '',
  99. devmaj: 0,
  100. devmin: 0,
  101. fill: '',
  102. 'NODETAR.depth': '1',
  103. 'NODETAR.type': 'File',
  104. nlink: 1,
  105. 'NODETAR.blksize': '4096',
  106. 'NODETAR.blocks': '8' } ]
  107. , [ 'entry',
  108. { path: 'fixtures/a.txt',
  109. mode: 420,
  110. uid: uid,
  111. gid: gid,
  112. size: 257,
  113. type: '0',
  114. linkpath: '',
  115. ustar: 'ustar\u0000',
  116. ustarver: '00',
  117. uname: '',
  118. gname: '',
  119. devmaj: 0,
  120. devmin: 0,
  121. fill: '' } ]
  122. , [ 'entry',
  123. { path: 'fixtures/b.txt',
  124. mode: 420,
  125. uid: uid,
  126. gid: gid,
  127. size: 512,
  128. type: '0',
  129. linkpath: '',
  130. ustar: 'ustar\u0000',
  131. ustarver: '00',
  132. uname: '',
  133. gname: '',
  134. devmaj: 0,
  135. devmin: 0,
  136. fill: '' } ]
  137. , [ 'entry',
  138. { path: 'fixtures/c.txt',
  139. mode: 420,
  140. uid: uid,
  141. gid: gid,
  142. size: 513,
  143. type: '0',
  144. linkpath: '',
  145. ustar: 'ustar\u0000',
  146. ustarver: '00',
  147. uname: '',
  148. gname: '',
  149. devmaj: 0,
  150. devmin: 0,
  151. fill: '' } ]
  152. , [ 'entry',
  153. { path: 'fixtures/cc.txt',
  154. mode: 420,
  155. uid: uid,
  156. gid: gid,
  157. size: 513,
  158. type: '0',
  159. linkpath: '',
  160. ustar: 'ustar\u0000',
  161. ustarver: '00',
  162. uname: '',
  163. gname: '',
  164. devmaj: 0,
  165. devmin: 0,
  166. fill: '' } ]
  167. , [ 'entry',
  168. { path: 'fixtures/dir/',
  169. mode: 488,
  170. uid: uid,
  171. gid: gid,
  172. size: 0,
  173. type: '5',
  174. linkpath: '',
  175. ustar: 'ustar\u0000',
  176. ustarver: '00',
  177. uname: '',
  178. gname: '',
  179. devmaj: 0,
  180. devmin: 0,
  181. fill: '' } ]
  182. , [ 'entry',
  183. { path: 'fixtures/dir/sub/',
  184. mode: 488,
  185. uid: uid,
  186. gid: gid,
  187. size: 0,
  188. type: '5',
  189. linkpath: '',
  190. ustar: 'ustar\u0000',
  191. ustarver: '00',
  192. uname: '',
  193. gname: '',
  194. devmaj: 0,
  195. devmin: 0,
  196. fill: '' } ]
  197. , [ 'entry',
  198. { path: 'fixtures/foo.js',
  199. mode: 420,
  200. uid: uid,
  201. gid: gid,
  202. size: 4,
  203. type: '0',
  204. linkpath: '',
  205. ustar: 'ustar\u0000',
  206. ustarver: '00',
  207. uname: '',
  208. gname: '',
  209. devmaj: 0,
  210. devmin: 0,
  211. fill: '' } ]
  212. , [ 'entry',
  213. { path: 'fixtures/hardlink-1',
  214. mode: 420,
  215. uid: uid,
  216. gid: gid,
  217. size: 200,
  218. type: '0',
  219. linkpath: '',
  220. ustar: 'ustar\u0000',
  221. ustarver: '00',
  222. uname: '',
  223. gname: '',
  224. devmaj: 0,
  225. devmin: 0,
  226. fill: '' } ]
  227. , [ 'entry',
  228. { path: 'fixtures/hardlink-2',
  229. mode: 420,
  230. uid: uid,
  231. gid: gid,
  232. size: 0,
  233. type: '1',
  234. linkpath: 'fixtures/hardlink-1',
  235. ustar: 'ustar\u0000',
  236. ustarver: '00',
  237. uname: '',
  238. gname: '',
  239. devmaj: 0,
  240. devmin: 0,
  241. fill: '' } ]
  242. , [ 'entry',
  243. { path: 'fixtures/omega.txt',
  244. mode: 420,
  245. uid: uid,
  246. gid: gid,
  247. size: 2,
  248. type: '0',
  249. linkpath: '',
  250. ustar: 'ustar\u0000',
  251. ustarver: '00',
  252. uname: '',
  253. gname: '',
  254. devmaj: 0,
  255. devmin: 0,
  256. fill: '' } ]
  257. , [ 'entry',
  258. { path: 'fixtures/packtest/',
  259. mode: 493,
  260. uid: uid,
  261. gid: gid,
  262. size: 0,
  263. type: '5',
  264. linkpath: '',
  265. ustar: 'ustar\u0000',
  266. ustarver: '00',
  267. uname: '',
  268. gname: '',
  269. devmaj: 0,
  270. devmin: 0,
  271. fill: '' } ]
  272. , [ 'entry',
  273. { path: 'fixtures/packtest/omega.txt',
  274. mode: 420,
  275. uid: uid,
  276. gid: gid,
  277. size: 2,
  278. type: '0',
  279. linkpath: '',
  280. ustar: 'ustar\u0000',
  281. ustarver: '00',
  282. uname: '',
  283. gname: '',
  284. devmaj: 0,
  285. devmin: 0,
  286. fill: '' } ]
  287. , [ 'entry',
  288. { path: 'fixtures/packtest/star.4.html',
  289. mode: 420,
  290. uid: uid,
  291. gid: gid,
  292. size: 54081,
  293. type: '0',
  294. linkpath: '',
  295. ustar: 'ustar\u0000',
  296. ustarver: '00',
  297. uname: '',
  298. gname: '',
  299. devmaj: 0,
  300. devmin: 0,
  301. fill: '' } ]
  302. , [ 'extendedHeader',
  303. { path: 'PaxHeader/fixtures/packtest/Ω.txt',
  304. mode: 420,
  305. uid: uid,
  306. gid: gid,
  307. type: 'x',
  308. linkpath: '',
  309. ustar: 'ustar\u0000',
  310. ustarver: '00',
  311. uname: '',
  312. gname: '',
  313. devmaj: 0,
  314. devmin: 0,
  315. fill: '' },
  316. { path: 'fixtures/packtest/Ω.txt',
  317. 'NODETAR.depth': '2',
  318. 'NODETAR.type': 'File',
  319. nlink: 1,
  320. uid: uid,
  321. gid: gid,
  322. size: 2,
  323. 'NODETAR.blksize': '4096',
  324. 'NODETAR.blocks': '8' } ]
  325. , [ 'entry',
  326. { path: 'fixtures/packtest/Ω.txt',
  327. mode: 420,
  328. uid: uid,
  329. gid: gid,
  330. size: 2,
  331. type: '0',
  332. linkpath: '',
  333. ustar: 'ustar\u0000',
  334. ustarver: '00',
  335. uname: '',
  336. gname: '',
  337. devmaj: 0,
  338. devmin: 0,
  339. fill: '',
  340. 'NODETAR.depth': '2',
  341. 'NODETAR.type': 'File',
  342. nlink: 1,
  343. 'NODETAR.blksize': '4096',
  344. 'NODETAR.blocks': '8' } ]
  345. , [ 'entry',
  346. { path: 'fixtures/r/',
  347. mode: 493,
  348. uid: uid,
  349. gid: gid,
  350. size: 0,
  351. type: '5',
  352. linkpath: '',
  353. ustar: 'ustar\u0000',
  354. ustarver: '00',
  355. uname: '',
  356. gname: '',
  357. devmaj: 0,
  358. devmin: 0,
  359. fill: '' } ]
  360. , [ 'entry',
  361. { path: 'fixtures/r/e/',
  362. mode: 493,
  363. uid: uid,
  364. gid: gid,
  365. size: 0,
  366. type: '5',
  367. linkpath: '',
  368. ustar: 'ustar\u0000',
  369. ustarver: '00',
  370. uname: '',
  371. gname: '',
  372. devmaj: 0,
  373. devmin: 0,
  374. fill: '' } ]
  375. , [ 'entry',
  376. { path: 'fixtures/r/e/a/',
  377. mode: 493,
  378. uid: uid,
  379. gid: gid,
  380. size: 0,
  381. type: '5',
  382. linkpath: '',
  383. ustar: 'ustar\u0000',
  384. ustarver: '00',
  385. uname: '',
  386. gname: '',
  387. devmaj: 0,
  388. devmin: 0,
  389. fill: '' } ]
  390. , [ 'entry',
  391. { path: 'fixtures/r/e/a/l/',
  392. mode: 493,
  393. uid: uid,
  394. gid: gid,
  395. size: 0,
  396. type: '5',
  397. linkpath: '',
  398. ustar: 'ustar\u0000',
  399. ustarver: '00',
  400. uname: '',
  401. gname: '',
  402. devmaj: 0,
  403. devmin: 0,
  404. fill: '' } ]
  405. , [ 'entry',
  406. { path: 'fixtures/r/e/a/l/l/',
  407. mode: 493,
  408. uid: uid,
  409. gid: gid,
  410. size: 0,
  411. type: '5',
  412. linkpath: '',
  413. ustar: 'ustar\u0000',
  414. ustarver: '00',
  415. uname: '',
  416. gname: '',
  417. devmaj: 0,
  418. devmin: 0,
  419. fill: '' } ]
  420. , [ 'entry',
  421. { path: 'fixtures/r/e/a/l/l/y/',
  422. mode: 493,
  423. uid: uid,
  424. gid: gid,
  425. size: 0,
  426. type: '5',
  427. linkpath: '',
  428. ustar: 'ustar\u0000',
  429. ustarver: '00',
  430. uname: '',
  431. gname: '',
  432. devmaj: 0,
  433. devmin: 0,
  434. fill: '' } ]
  435. , [ 'entry',
  436. { path: 'fixtures/r/e/a/l/l/y/-/',
  437. mode: 493,
  438. uid: uid,
  439. gid: gid,
  440. size: 0,
  441. type: '5',
  442. linkpath: '',
  443. ustar: 'ustar\u0000',
  444. ustarver: '00',
  445. uname: '',
  446. gname: '',
  447. devmaj: 0,
  448. devmin: 0,
  449. fill: '' } ]
  450. , [ 'entry',
  451. { path: 'fixtures/r/e/a/l/l/y/-/d/',
  452. mode: 493,
  453. uid: uid,
  454. gid: gid,
  455. size: 0,
  456. type: '5',
  457. linkpath: '',
  458. ustar: 'ustar\u0000',
  459. ustarver: '00',
  460. uname: '',
  461. gname: '',
  462. devmaj: 0,
  463. devmin: 0,
  464. fill: '' } ]
  465. , [ 'entry',
  466. { path: 'fixtures/r/e/a/l/l/y/-/d/e/',
  467. mode: 493,
  468. uid: uid,
  469. gid: gid,
  470. size: 0,
  471. type: '5',
  472. linkpath: '',
  473. ustar: 'ustar\u0000',
  474. ustarver: '00',
  475. uname: '',
  476. gname: '',
  477. devmaj: 0,
  478. devmin: 0,
  479. fill: '' } ]
  480. , [ 'entry',
  481. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/',
  482. mode: 493,
  483. uid: uid,
  484. gid: gid,
  485. size: 0,
  486. type: '5',
  487. linkpath: '',
  488. ustar: 'ustar\u0000',
  489. ustarver: '00',
  490. uname: '',
  491. gname: '',
  492. devmaj: 0,
  493. devmin: 0,
  494. fill: '' } ]
  495. , [ 'entry',
  496. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/',
  497. mode: 493,
  498. uid: uid,
  499. gid: gid,
  500. size: 0,
  501. type: '5',
  502. linkpath: '',
  503. ustar: 'ustar\u0000',
  504. ustarver: '00',
  505. uname: '',
  506. gname: '',
  507. devmaj: 0,
  508. devmin: 0,
  509. fill: '' } ]
  510. , [ 'entry',
  511. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/',
  512. mode: 493,
  513. uid: uid,
  514. gid: gid,
  515. size: 0,
  516. type: '5',
  517. linkpath: '',
  518. ustar: 'ustar\u0000',
  519. ustarver: '00',
  520. uname: '',
  521. gname: '',
  522. devmaj: 0,
  523. devmin: 0,
  524. fill: '' } ]
  525. , [ 'entry',
  526. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/',
  527. mode: 493,
  528. uid: uid,
  529. gid: gid,
  530. size: 0,
  531. type: '5',
  532. linkpath: '',
  533. ustar: 'ustar\u0000',
  534. ustarver: '00',
  535. uname: '',
  536. gname: '',
  537. devmaj: 0,
  538. devmin: 0,
  539. fill: '' } ]
  540. , [ 'entry',
  541. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/',
  542. mode: 493,
  543. uid: uid,
  544. gid: gid,
  545. size: 0,
  546. type: '5',
  547. linkpath: '',
  548. ustar: 'ustar\u0000',
  549. ustarver: '00',
  550. uname: '',
  551. gname: '',
  552. devmaj: 0,
  553. devmin: 0,
  554. fill: '' } ]
  555. , [ 'entry',
  556. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/',
  557. mode: 493,
  558. uid: uid,
  559. gid: gid,
  560. size: 0,
  561. type: '5',
  562. linkpath: '',
  563. ustar: 'ustar\u0000',
  564. ustarver: '00',
  565. uname: '',
  566. gname: '',
  567. devmaj: 0,
  568. devmin: 0,
  569. fill: '' } ]
  570. , [ 'entry',
  571. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/',
  572. mode: 493,
  573. uid: uid,
  574. gid: gid,
  575. size: 0,
  576. type: '5',
  577. linkpath: '',
  578. ustar: 'ustar\u0000',
  579. ustarver: '00',
  580. uname: '',
  581. gname: '',
  582. devmaj: 0,
  583. devmin: 0,
  584. fill: '' } ]
  585. , [ 'entry',
  586. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/',
  587. mode: 493,
  588. uid: uid,
  589. gid: gid,
  590. size: 0,
  591. type: '5',
  592. linkpath: '',
  593. ustar: 'ustar\u0000',
  594. ustarver: '00',
  595. uname: '',
  596. gname: '',
  597. devmaj: 0,
  598. devmin: 0,
  599. fill: '' } ]
  600. , [ 'entry',
  601. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/',
  602. mode: 493,
  603. uid: uid,
  604. gid: gid,
  605. size: 0,
  606. type: '5',
  607. linkpath: '',
  608. ustar: 'ustar\u0000',
  609. ustarver: '00',
  610. uname: '',
  611. gname: '',
  612. devmaj: 0,
  613. devmin: 0,
  614. fill: '' } ]
  615. , [ 'entry',
  616. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/',
  617. mode: 493,
  618. uid: uid,
  619. gid: gid,
  620. size: 0,
  621. type: '5',
  622. linkpath: '',
  623. ustar: 'ustar\u0000',
  624. ustarver: '00',
  625. uname: '',
  626. gname: '',
  627. devmaj: 0,
  628. devmin: 0,
  629. fill: '' } ]
  630. , [ 'entry',
  631. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/',
  632. mode: 493,
  633. uid: uid,
  634. gid: gid,
  635. size: 0,
  636. type: '5',
  637. linkpath: '',
  638. ustar: 'ustar\u0000',
  639. ustarver: '00',
  640. uname: '',
  641. gname: '',
  642. devmaj: 0,
  643. devmin: 0,
  644. fill: '' } ]
  645. , [ 'entry',
  646. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/',
  647. mode: 493,
  648. uid: uid,
  649. gid: gid,
  650. size: 0,
  651. type: '5',
  652. linkpath: '',
  653. ustar: 'ustar\u0000',
  654. ustarver: '00',
  655. uname: '',
  656. gname: '',
  657. devmaj: 0,
  658. devmin: 0,
  659. fill: '' } ]
  660. , [ 'entry',
  661. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/',
  662. mode: 493,
  663. uid: uid,
  664. gid: gid,
  665. size: 0,
  666. type: '5',
  667. linkpath: '',
  668. ustar: 'ustar\u0000',
  669. ustarver: '00',
  670. uname: '',
  671. gname: '',
  672. devmaj: 0,
  673. devmin: 0,
  674. fill: '' } ]
  675. , [ 'entry',
  676. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/',
  677. mode: 493,
  678. uid: uid,
  679. gid: gid,
  680. size: 0,
  681. type: '5',
  682. linkpath: '',
  683. ustar: 'ustar\u0000',
  684. ustarver: '00',
  685. uname: '',
  686. gname: '',
  687. devmaj: 0,
  688. devmin: 0,
  689. fill: '' } ]
  690. , [ 'entry',
  691. { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
  692. mode: 420,
  693. uid: uid,
  694. gid: gid,
  695. size: 100,
  696. type: '0',
  697. linkpath: '',
  698. ustar: 'ustar\u0000',
  699. ustarver: '00',
  700. uname: '',
  701. gname: '',
  702. devmaj: 0,
  703. devmin: 0,
  704. fill: '' } ]
  705. , [ 'entry',
  706. { path: 'fixtures/symlink',
  707. uid: uid,
  708. gid: gid,
  709. size: 0,
  710. type: '2',
  711. linkpath: 'hardlink-1',
  712. ustar: 'ustar\u0000',
  713. ustarver: '00',
  714. uname: '',
  715. gname: '',
  716. devmaj: 0,
  717. devmin: 0,
  718. fill: '' } ]
  719. , [ 'extendedHeader',
  720. { path: 'PaxHeader/fixtures/Ω.txt',
  721. mode: 420,
  722. uid: uid,
  723. gid: gid,
  724. type: 'x',
  725. linkpath: '',
  726. ustar: 'ustar\u0000',
  727. ustarver: '00',
  728. uname: '',
  729. gname: '',
  730. devmaj: 0,
  731. devmin: 0,
  732. fill: '' },
  733. { path: "fixtures/Ω.txt"
  734. , "NODETAR.depth": "1"
  735. , "NODETAR.type": "File"
  736. , nlink: 1
  737. , uid: uid
  738. , gid: gid
  739. , size: 2
  740. , "NODETAR.blksize": "4096"
  741. , "NODETAR.blocks": "8" } ]
  742. , [ 'entry',
  743. { path: 'fixtures/Ω.txt',
  744. mode: 420,
  745. uid: uid,
  746. gid: gid,
  747. size: 2,
  748. type: '0',
  749. linkpath: '',
  750. ustar: 'ustar\u0000',
  751. ustarver: '00',
  752. uname: '',
  753. gname: '',
  754. devmaj: 0,
  755. devmin: 0,
  756. fill: '',
  757. 'NODETAR.depth': '1',
  758. 'NODETAR.type': 'File',
  759. nlink: 1,
  760. 'NODETAR.blksize': '4096',
  761. 'NODETAR.blocks': '8' } ]
  762. ]
  763. // first, make sure that the hardlinks are actually hardlinks, or this
  764. // won't work. Git has a way of replacing them with a copy.
  765. var hard1 = path.resolve(__dirname, "fixtures/hardlink-1")
  766. , hard2 = path.resolve(__dirname, "fixtures/hardlink-2")
  767. , fs = require("fs")
  768. try { fs.unlinkSync(hard2) } catch (e) {}
  769. fs.linkSync(hard1, hard2)
  770. tap.test("with global header", { timeout: 10000 }, function (t) {
  771. runTest(t, true)
  772. })
  773. tap.test("without global header", { timeout: 10000 }, function (t) {
  774. runTest(t, false)
  775. })
  776. tap.test("with from base", { timeout: 10000 }, function (t) {
  777. runTest(t, true, true)
  778. })
  779. function alphasort (a, b) {
  780. return a === b ? 0
  781. : a.toLowerCase() > b.toLowerCase() ? 1
  782. : a.toLowerCase() < b.toLowerCase() ? -1
  783. : a > b ? 1
  784. : -1
  785. }
  786. function runTest (t, doGH, doFromBase) {
  787. var reader = Reader({ path: input
  788. , filter: function () {
  789. return !this.path.match(/\.(tar|hex)$/)
  790. }
  791. , sort: alphasort
  792. })
  793. var props = doGH ? pkg : {}
  794. if(doFromBase) props.fromBase = true;
  795. var pack = Pack(props)
  796. var writer = Writer(target)
  797. // skip the global header if we're not doing that.
  798. var entry = doGH ? 0 : 1
  799. t.ok(reader, "reader ok")
  800. t.ok(pack, "pack ok")
  801. t.ok(writer, "writer ok")
  802. pack.pipe(writer)
  803. var parse = tar.Parse()
  804. t.ok(parse, "parser should be ok")
  805. pack.on("data", function (c) {
  806. // console.error("PACK DATA")
  807. if (c.length !== 512) {
  808. // this one is too noisy, only assert if it'll be relevant
  809. t.equal(c.length, 512, "parser should emit data in 512byte blocks")
  810. }
  811. parse.write(c)
  812. })
  813. pack.on("end", function () {
  814. // console.error("PACK END")
  815. t.pass("parser ends")
  816. parse.end()
  817. })
  818. pack.on("error", function (er) {
  819. t.fail("pack error", er)
  820. })
  821. parse.on("error", function (er) {
  822. t.fail("parse error", er)
  823. })
  824. writer.on("error", function (er) {
  825. t.fail("writer error", er)
  826. })
  827. reader.on("error", function (er) {
  828. t.fail("reader error", er)
  829. })
  830. parse.on("*", function (ev, e) {
  831. var wanted = entries[entry++]
  832. if (!wanted) {
  833. t.fail("unexpected event: "+ev)
  834. return
  835. }
  836. t.equal(ev, wanted[0], "event type should be "+wanted[0])
  837. if(doFromBase) {
  838. if(wanted[1].path.indexOf('fixtures/') && wanted[1].path.length == 100)
  839. wanted[1].path = wanted[1].path.replace('fixtures/', '') + 'ccccccccc'
  840. if(wanted[1]) wanted[1].path = wanted[1].path.replace('fixtures/', '').replace('//', '/')
  841. if(wanted[1].path == '') wanted[1].path = '/'
  842. if(wanted[2] && wanted[2].path) wanted[2].path = wanted[2].path.replace('fixtures', '').replace(/^\//, '')
  843. wanted[1].linkpath = wanted[1].linkpath.replace('fixtures/', '')
  844. }
  845. if (ev !== wanted[0] || e.path !== wanted[1].path) {
  846. console.error("wanted", wanted)
  847. console.error([ev, e.props])
  848. e.on("end", function () {
  849. console.error(e.fields)
  850. throw "break"
  851. })
  852. }
  853. t.has(e.props, wanted[1], "properties "+wanted[1].path)
  854. if (wanted[2]) {
  855. e.on("end", function () {
  856. if (!e.fields) {
  857. t.ok(e.fields, "should get fields")
  858. } else {
  859. t.has(e.fields, wanted[2], "should get expected fields")
  860. }
  861. })
  862. }
  863. })
  864. reader.pipe(pack)
  865. writer.on("close", function () {
  866. t.equal(entry, entries.length, "should get all expected entries")
  867. t.pass("it finished")
  868. t.end()
  869. })
  870. }