pack-no-proprietary.js 19 KB

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