@@ -14,15 +14,16 @@ const CACHE = path.join(testDir, 'cache')
14
14
const contentPath = require ( '../lib/content/path' )
15
15
const Dir = Tacks . Dir
16
16
const File = Tacks . File
17
- const putStream = require ( '../lib/content/put-stream' )
17
+
18
+ const write = require ( '../lib/content/write' )
18
19
19
20
test ( 'basic put' , function ( t ) {
20
21
const CONTENT = 'foobarbaz'
21
22
// Default is sha512
22
23
const DIGEST = crypto . createHash ( 'sha512' ) . update ( CONTENT ) . digest ( 'hex' )
23
24
let foundDigest
24
25
const src = fromString ( CONTENT )
25
- const stream = putStream ( CACHE ) . on ( 'digest' , function ( d ) {
26
+ const stream = write . stream ( CACHE ) . on ( 'digest' , function ( d ) {
26
27
foundDigest = d
27
28
} )
28
29
pipe ( src , stream , function ( err ) {
@@ -47,7 +48,7 @@ test('checks input digest doesn\'t match data', function (t) {
47
48
t . plan ( 5 )
48
49
let foundDigest1
49
50
let foundDigest2
50
- pipe ( fromString ( 'bazbarfoo' ) , putStream ( CACHE , {
51
+ pipe ( fromString ( 'bazbarfoo' ) , write . stream ( CACHE , {
51
52
digest : DIGEST
52
53
} ) . on ( 'digest' , function ( d ) {
53
54
foundDigest1 = d
@@ -56,7 +57,7 @@ test('checks input digest doesn\'t match data', function (t) {
56
57
t . ok ( ! ! err , 'got an error' )
57
58
t . equal ( err . code , 'EBADCHECKSUM' , 'returns a useful error code' )
58
59
} )
59
- pipe ( fromString ( CONTENT ) , putStream ( CACHE , {
60
+ pipe ( fromString ( CONTENT ) , write . stream ( CACHE , {
60
61
digest : DIGEST
61
62
} ) . on ( 'digest' , function ( d ) {
62
63
foundDigest2 = d
@@ -68,7 +69,7 @@ test('checks input digest doesn\'t match data', function (t) {
68
69
69
70
test ( 'errors if stream ends with no data' , function ( t ) {
70
71
let foundDigest = null
71
- pipe ( fromString ( '' ) , putStream ( CACHE ) . on ( 'digest' , function ( d ) {
72
+ pipe ( fromString ( '' ) , write . stream ( CACHE ) . on ( 'digest' , function ( d ) {
72
73
foundDigest = d
73
74
} ) , function ( err ) {
74
75
t . ok ( err , 'got an error' )
@@ -81,7 +82,7 @@ test('errors if stream ends with no data', function (t) {
81
82
test ( 'errors if input size does not match expected' , function ( t ) {
82
83
t . plan ( 10 )
83
84
let dig1 = null
84
- pipe ( fromString ( 'abc' ) , putStream ( CACHE , {
85
+ pipe ( fromString ( 'abc' ) , write . stream ( CACHE , {
85
86
size : 5
86
87
} ) . on ( 'digest' , function ( d ) {
87
88
dig1 = d
@@ -93,7 +94,7 @@ test('errors if input size does not match expected', function (t) {
93
94
t . equal ( err . found , 3 , 'error includes found size' )
94
95
} )
95
96
let dig2 = null
96
- pipe ( fromString ( 'abcdefghi' ) , putStream ( CACHE , {
97
+ pipe ( fromString ( 'abcdefghi' ) , write . stream ( CACHE , {
97
98
size : 5
98
99
} ) . on ( 'digest' , function ( d ) {
99
100
dig2 = d
@@ -119,7 +120,7 @@ test('does not overwrite content if already on disk', function (t) {
119
120
let dig1
120
121
let dig2
121
122
// With a digest -- early short-circuiting
122
- pipe ( fromString ( CONTENT ) , putStream ( CACHE , {
123
+ pipe ( fromString ( CONTENT ) , write . stream ( CACHE , {
123
124
digest : DIGEST
124
125
} ) . on ( 'digest' , function ( d ) {
125
126
dig1 = d
@@ -131,7 +132,7 @@ test('does not overwrite content if already on disk', function (t) {
131
132
t . equal ( d , 'nope' , 'process short-circuited. Data not written.' )
132
133
} )
133
134
} )
134
- pipe ( fromString ( CONTENT ) , putStream ( CACHE ) . on ( 'digest' , function ( d ) {
135
+ pipe ( fromString ( CONTENT ) , write . stream ( CACHE ) . on ( 'digest' , function ( d ) {
135
136
dig2 = d
136
137
} ) , function ( err ) {
137
138
if ( err ) { throw err }
@@ -147,7 +148,7 @@ test('errors if input stream errors', function (t) {
147
148
const stream = fromString ( 'foobarbaz' )
148
149
. on ( 'end' , ( ) => stream . emit ( 'error' , new Error ( 'bleh' ) ) )
149
150
let foundDigest
150
- const putter = putStream ( CACHE ) . on ( 'digest' , function ( d ) {
151
+ const putter = write . stream ( CACHE ) . on ( 'digest' , function ( d ) {
151
152
foundDigest = d
152
153
} )
153
154
pipe ( stream , putter , function ( err ) {
@@ -177,7 +178,7 @@ test('exits normally if file already open', function (t) {
177
178
// Generally, you'd get an EBUSY back.
178
179
fs . open ( PATH , 'r+' , function ( err , fd ) {
179
180
if ( err ) { throw err }
180
- pipe ( fromString ( CONTENT ) , putStream ( CACHE ) . on ( 'digest' , function ( d ) {
181
+ pipe ( fromString ( CONTENT ) , write . stream ( CACHE ) . on ( 'digest' , function ( d ) {
181
182
foundDigest = d
182
183
} ) , function ( err ) {
183
184
if ( err ) { throw err }
@@ -195,7 +196,7 @@ test('exits normally if file already open', function (t) {
195
196
196
197
test ( 'cleans up tmp on successful completion' , function ( t ) {
197
198
const CONTENT = 'foobarbaz'
198
- pipe ( fromString ( CONTENT ) , putStream ( CACHE ) , function ( err ) {
199
+ pipe ( fromString ( CONTENT ) , write . stream ( CACHE ) , function ( err ) {
199
200
if ( err ) { throw err }
200
201
const tmp = path . join ( CACHE , 'tmp' )
201
202
fs . readdir ( tmp , function ( err , files ) {
@@ -212,7 +213,7 @@ test('cleans up tmp on successful completion', function (t) {
212
213
213
214
test ( 'cleans up tmp on error' , function ( t ) {
214
215
const CONTENT = 'foobarbaz'
215
- pipe ( fromString ( CONTENT ) , putStream ( CACHE , { size : 1 } ) , function ( err ) {
216
+ pipe ( fromString ( CONTENT ) , write . stream ( CACHE , { size : 1 } ) , function ( err ) {
216
217
t . ok ( err , 'got an error' )
217
218
t . equal ( err . code , 'EBADSIZE' , 'got expected code' )
218
219
const tmp = path . join ( CACHE , 'tmp' )
@@ -234,7 +235,7 @@ test('checks the size of stream data if opts.size provided', function (t) {
234
235
t . plan ( 8 )
235
236
pipe (
236
237
fromString ( CONTENT . slice ( 3 ) ) ,
237
- putStream ( CACHE , {
238
+ write . stream ( CACHE , {
238
239
size : CONTENT . length
239
240
} ) . on ( 'digest' , function ( d ) { dig1 = d } ) ,
240
241
function ( err ) {
@@ -245,7 +246,7 @@ test('checks the size of stream data if opts.size provided', function (t) {
245
246
)
246
247
pipe (
247
248
fromString ( CONTENT + 'quux' ) ,
248
- putStream ( CACHE , {
249
+ write . stream ( CACHE , {
249
250
size : CONTENT . length
250
251
} ) . on ( 'digest' , function ( d ) { dig2 = d } ) ,
251
252
function ( err ) {
@@ -256,7 +257,7 @@ test('checks the size of stream data if opts.size provided', function (t) {
256
257
)
257
258
pipe (
258
259
fromString ( CONTENT ) ,
259
- putStream ( CACHE , {
260
+ write . stream ( CACHE , {
260
261
size : CONTENT . length
261
262
} ) . on ( 'digest' , function ( d ) { dig3 = d } ) ,
262
263
function ( err ) {
0 commit comments