Initial commit
[yaffs-website] / node_modules / tar / test / header.js
1 var tap = require("tap")
2 var TarHeader = require("../lib/header.js")
3 var tar = require("../tar.js")
4 var fs = require("fs")
5
6
7 var headers =
8   { "a.txt file header":
9     [ "612e747874000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030303036343420003035373736312000303030303234200030303030303030303430312031313635313336303333332030313234353100203000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000757374617200303069736161637300000000000000000000000000000000000000000000000000007374616666000000000000000000000000000000000000000000000000000000303030303030200030303030303020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
10     , { cksumValid: true
11       , path: 'a.txt'
12       , mode: 420
13       , uid: 24561
14       , gid: 20
15       , size: 257
16       , mtime: 1319493851
17       , cksum: 5417
18       , type: '0'
19       , linkpath: ''
20       , ustar: 'ustar\0'
21       , ustarver: '00'
22       , uname: 'isaacs'
23       , gname: 'staff'
24       , devmaj: 0
25       , devmin: 0
26       , fill: '' }
27     ]
28
29   , "omega pax": // the extended header from omega tar.
30     [ "5061784865616465722fcea92e74787400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030303036343420003035373736312000303030303234200030303030303030303137302031313534333731303631312030313530353100207800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000757374617200303069736161637300000000000000000000000000000000000000000000000000007374616666000000000000000000000000000000000000000000000000000000303030303030200030303030303020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
31     , { cksumValid: true
32       , path: 'PaxHeader/Ω.txt'
33       , mode: 420
34       , uid: 24561
35       , gid: 20
36       , size: 120
37       , mtime: 1301254537
38       , cksum: 6697
39       , type: 'x'
40       , linkpath: ''
41       , ustar: 'ustar\0'
42       , ustarver: '00'
43       , uname: 'isaacs'
44       , gname: 'staff'
45       , devmaj: 0
46       , devmin: 0
47       , fill: '' } ]
48
49   , "omega file header":
50     [ "cea92e7478740000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030303036343420003035373736312000303030303234200030303030303030303030322031313534333731303631312030313330373200203000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000757374617200303069736161637300000000000000000000000000000000000000000000000000007374616666000000000000000000000000000000000000000000000000000000303030303030200030303030303020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
51     , { cksumValid: true
52       , path: 'Ω.txt'
53       , mode: 420
54       , uid: 24561
55       , gid: 20
56       , size: 2
57       , mtime: 1301254537
58       , cksum: 5690
59       , type: '0'
60       , linkpath: ''
61       , ustar: 'ustar\0'
62       , ustarver: '00'
63       , uname: 'isaacs'
64       , gname: 'staff'
65       , devmaj: 0
66       , devmin: 0
67       , fill: '' } ]
68
69   , "foo.js file header":
70     [ "666f6f2e6a730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030303036343420003035373736312000303030303234200030303030303030303030342031313534333637303734312030313236313700203000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000757374617200303069736161637300000000000000000000000000000000000000000000000000007374616666000000000000000000000000000000000000000000000000000000303030303030200030303030303020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
71     , { cksumValid: true
72       , path: 'foo.js'
73       , mode: 420
74       , uid: 24561
75       , gid: 20
76       , size: 4
77       , mtime: 1301246433
78       , cksum: 5519
79       , type: '0'
80       , linkpath: ''
81       , ustar: 'ustar\0'
82       , ustarver: '00'
83       , uname: 'isaacs'
84       , gname: 'staff'
85       , devmaj: 0
86       , devmin: 0
87       , fill: '' }
88     ]
89
90   , "b.txt file header":
91     [ "622e747874000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030303036343420003035373736312000303030303234200030303030303030313030302031313635313336303637372030313234363100203000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000757374617200303069736161637300000000000000000000000000000000000000000000000000007374616666000000000000000000000000000000000000000000000000000000303030303030200030303030303020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
92     , { cksumValid: true
93       , path: 'b.txt'
94       , mode: 420
95       , uid: 24561
96       , gid: 20
97       , size: 512
98       , mtime: 1319494079
99       , cksum: 5425
100       , type: '0'
101       , linkpath: ''
102       , ustar: 'ustar\0'
103       , ustarver: '00'
104       , uname: 'isaacs'
105       , gname: 'staff'
106       , devmaj: 0
107       , devmin: 0
108       , fill: '' }
109     ]
110
111   , "deep nested file":
112     [ "636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363636363633030303634342000303537373631200030303030323420003030303030303030313434203131363532313531353333203034333331340020300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000075737461720030306973616163730000000000000000000000000000000000000000000000000000737461666600000000000000000000000000000000000000000000000000000030303030303020003030303030302000722f652f612f6c2f6c2f792f2d2f642f652f652f702f2d2f662f6f2f6c2f642f652f722f2d2f702f612f742f680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
113     , { cksumValid: true,
114         path: 'r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'
115       , mode: 420
116       , uid: 24561
117       , gid: 20
118       , size: 100
119       , mtime: 1319687003
120       , cksum: 18124
121       , type: '0'
122       , linkpath: ''
123       , ustar: 'ustar\0'
124       , ustarver: '00'
125       , uname: 'isaacs'
126       , gname: 'staff'
127       , devmaj: 0
128       , devmin: 0
129       , fill: '' }
130     ]
131   }
132
133 tap.test("parsing", function (t) {
134   Object.keys(headers).forEach(function (name) {
135     var h = headers[name]
136       , header = new Buffer(h[0], "hex")
137       , expect = h[1]
138       , parsed = new TarHeader(header)
139
140     // console.error(parsed)
141     t.has(parsed, expect, "parse " + name)
142   })
143   t.end()
144 })
145
146 tap.test("encoding", function (t) {
147   Object.keys(headers).forEach(function (name) {
148     var h = headers[name]
149       , expect = new Buffer(h[0], "hex")
150       , encoded = TarHeader.encode(h[1])
151
152     // might have slightly different bytes, since the standard
153     // isn't very strict, but should have the same semantics
154     // checkSum will be different, but cksumValid will be true
155
156     var th = new TarHeader(encoded)
157     delete h[1].block
158     delete h[1].needExtended
159     delete h[1].cksum
160     t.has(th, h[1], "fields "+name)
161   })
162   t.end()
163 })
164
165 // test these manually.  they're a bit rare to find in the wild
166 tap.test("parseNumeric tests", function (t) {
167   var parseNumeric = TarHeader.parseNumeric
168     , numbers =
169       { "303737373737373700": 2097151
170       , "30373737373737373737373700": 8589934591
171       , "303030303036343400": 420
172       , "800000ffffffffffff": 281474976710655
173       , "ffffff000000000001": -281474976710654
174       , "ffffff000000000000": -281474976710655
175       , "800000000000200000": 2097152
176       , "8000000000001544c5": 1393861
177       , "ffffffffffff1544c5": -15383354 }
178   Object.keys(numbers).forEach(function (n) {
179     var b = new Buffer(n, "hex")
180     t.equal(parseNumeric(b), numbers[n], n + " === " + numbers[n])
181   })
182   t.end()
183 })