Skip to content
This repository was archived by the owner on Jul 3, 2019. It is now read-only.

Commit 8ffb7fa

Browse files
committed
fix(docs): Missed spots in README
1 parent 1aef3e5 commit 8ffb7fa

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

README.md

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# cacache [![npm version](https://img.shields.io/npm/v/cacache.svg)](https://npm.im/cacache) [![license](https://img.shields.io/npm/l/cacache.svg)](https://npm.im/cacache) [![Travis](https://img.shields.io/travis/zkat/cacache.svg)](https://travis-ci.org/zkat/cacache) [![AppVeyor](https://ci.appveyor.com/api/projects/status/github/zkat/cacache?svg=true)](https://ci.appveyor.com/project/zkat/cacache) [![Coverage Status](https://coveralls.io/repos/github/zkat/cacache/badge.svg?branch=latest)](https://coveralls.io/github/zkat/cacache?branch=latest)
22

33
[`cacache`](https://github.com/zkat/cacache) is a Node.js library for managing
4-
caches of keyed data that can be looked up both by key and by a digest of the
5-
content itself. This means that by-content lookups can be very very fast, and
6-
that stored content is shared by different keys if they point to the same data.
4+
local key and content address caches. It's really fast, really good at
5+
concurrency, and it will never give you corrupted data, even if cache files
6+
get corrupted or manipulated.
7+
8+
It was originally written to be used as [npm](https://npm.im)'s local cache, but
9+
can just as easily be used on its own
710

811
## Install
912

@@ -41,19 +44,14 @@ const key = 'my-unique-key-1234'
4144
let tarballDigest = null
4245

4346
// Cache it! Use `cachePath` as the root of the content cache
44-
fs.createReadStream(
45-
tarball
46-
).pipe(
47-
cacache.put.stream(
48-
cachePath, key
49-
).on('digest', (d) => tarballDigest = d)
50-
).on('finish', function () {
51-
console.log(`Saved ${tarball} to ${cachePath}.`)
47+
cacache.put(cachePath, key, '10293801983029384').then(digest => {
48+
console.log(`Saved content to ${cachePath}.`)
5249
})
5350

5451
const destination = '/tmp/mytar.tgz'
5552

5653
// Copy the contents out of the cache and into their destination!
54+
// But this time, use stream instead!
5755
cacache.get.stream(
5856
cachePath, key
5957
).pipe(
@@ -63,23 +61,24 @@ cacache.get.stream(
6361
})
6462

6563
// The same thing, but skip the key index.
66-
cacache.get.stream.byDigest(
67-
cachePath, tarballDigest
68-
).pipe(
69-
fs.createWriteStream(destination)
70-
).on('finish', () => {
71-
console.log('done extracting using sha1!')
64+
cacache.get.byDigest(cachePath, tarballSha512).then(data => {
65+
fs.writeFile(destination, data, err => {
66+
console.log('tarball data fetched based on its sha512sum and written out!')
67+
})
7268
})
7369
```
7470

7571
### Features
7672

77-
* Extraction by key or by content digest (shasum, etc).
78-
* Deduplicated content by digest -- two inputs with same key are only saved once
79-
* Consistency checks, both on insert and extract.
80-
* (Kinda) concurrency-safe and fault tolerant.
81-
* Streaming support.
82-
* Metadata storage.
73+
* Extraction by key or by content address (shasum, etc)
74+
* Multi-hash support - safely host sha1, sha512, etc, in a single cache
75+
* Automatic content deduplication
76+
* Fault tolerance and consistency guarantees for both insertion and extraction
77+
* Lockless, high-concurrency cache access
78+
* Streaming support
79+
* Promise support
80+
* Arbitrary metadata storage
81+
* Garbage collection and additional offline verification
8382

8483
### Contributing
8584

@@ -102,7 +101,8 @@ cacache.ls(cachePath).then(console.log)
102101
'my-thing': {
103102
key: 'my-thing',
104103
digest: 'deadbeef',
105-
path: '.testcache/content/deadbeef',
104+
hashAlgorithm: 'sha512',
105+
path: '.testcache/content/deadbeef', // joined with `cachePath`
106106
time: 12345698490,
107107
metadata: {
108108
name: 'blah',
@@ -113,18 +113,21 @@ cacache.ls(cachePath).then(console.log)
113113
'other-thing': {
114114
key: 'other-thing',
115115
digest: 'bada55',
116+
hashAlgorithm: 'whirlpool',
116117
path: '.testcache/content/bada55',
117118
time: 11992309289
118119
}
119120
}
120121
```
121122

122-
#### <a name="get-data"></a> `> cacache.get(cache, key, [opts]) -> Promise({data, metadata, digest})`
123+
#### <a name="get-data"></a> `> cacache.get(cache, key, [opts]) -> Promise({data, metadata, digest, hashAlgorithm})`
123124

124125
Returns an object with the cached data, digest, and metadata identified by
125126
`key`. The `data` property of this object will be a `Buffer` instance that
126127
presumably holds some data that means something to you. I'm sure you know what
127-
to do with it! cacache just won't care.
128+
to do with it! cacache just won't care. `hashAlgorithm` is the algorithm used
129+
to calculate the `digest` of the content. This algorithm must be used if you
130+
fetch later with `get.byDigest`.
128131

129132
If there is no content identified by `key`, or if the locally-stored data does
130133
not pass the validity checksum, the promise will be rejected.
@@ -250,9 +253,7 @@ cache entry has been successfully written.
250253
fetch(
251254
'https://registry.npmjs.org/cacache/-/cacache-1.0.0.tgz'
252255
).then(data => {
253-
cacache.put(
254-
cachePath, 'registry.npmjs.org|cacache@1.0.0', data
255-
)
256+
return cacache.put(cachePath, 'registry.npmjs.org|cacache@1.0.0', data)
256257
}).then(digest => {
257258
console.log('digest is', digest)
258259
})

0 commit comments

Comments
 (0)