forked from andreialecu/s3-sync-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
36 lines (32 loc) · 894 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var db = require('level')('.cache')
var readdirp = require('readdirp')
var s3sync = require('./')
// To be updated with your own configuration
var syncer = s3sync(db, {
key: process.env.AWS_ACCESS_KEY
, secret: process.env.AWS_SECRET_KEY
, bucket: process.env.AWS_BUCKET
})
console.error('cache downloading...')
syncer.getCache(function(err) {
if (err) throw err
// It's important that this stream
// gets created in the same tick you
// pipe it to syncer.
var files = readdirp({
root: __dirname + '/node_modules'
})
console.error('cache downloaded!')
files.pipe(syncer)
.on('data', function(d) {
console.log(d.fullPath + ' -> ' + d.url)
})
.once('end', function() {
console.error('uploading new cache')
syncer.putCache(function(err) {
if (err) throw err
console.error('done!')
db.close()
})
})
})