Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New cache approach

  • Loading branch information...
commit 988061ccbce4201b636170eab3a633df4cb25b86 1 parent a0151f0
@isaacs isaacs authored
Showing with 86 additions and 19 deletions.
  1. +86 −19 lib/cache.js
View
105 lib/cache.js
@@ -1,29 +1,96 @@
-// XXX lib/utils/tar.js and this file need to be rewritten.
-
/*
-adding a folder:
-1. tar into tmp/random/package.tgz
-2. untar into tmp/random/contents/package, stripping one dir piece
-3. tar tmp/random/contents/package to cache/n/v/package.tgz
-4. untar cache/n/v/package.tgz into cache/n/v/package
-5. rm tmp/random
-
-Adding a url:
-1. fetch to tmp/random/package.tgz
-2. goto folder(2)
-
-adding a name@version:
+
+Each add function calls the cb with:
+* error
+* package.json data
+* a stream of the gzipped tarball
+
+add a local path:
+1. stat
+2. switch(file type)
+ file: add local file
+ folder: add local folder
+
+add a local folder:
+1. read folder/package.json
+2. p = tar.Pack(folder)
+3. g = Gzip
+3. p.pipe g.pipe cache/n/v/package.tgz
+3. p.pipe tar.Extract( cache/n/v/package/ )
+4. cb(null, data, g)
+
+add unknown stream:
+1. buffer first 512 bytes.
+2. if totalSize % 512 === 0 and parses as tar header,
+ add local tar
+3. if first three bytes are [0x1F,0x8B,0x08]
+ add local tgz
+4. else add local js
+5. re-emit buffered bytes
+
+add registry url, data, (shasum):
+1. s = request(url)
+2. if shasum, s.pipe shasum checker
+3. s.pipe tar.Extract(cache/n/v/package)
+4. s.pipe cache/n/v/package.tgz
+5. cb(null, data, s)
+
+add url:
+1. add unknown stream( request(url) )
+
+add js stream:
+1. buffer until we have a package comment
+2. parse package comment
+3. pipe to cache/n/v/package/index.js
+4. re-emit buffered bytes
+5. var p = tar.Pack(cache/n/v/package)
+6. p.pipe gzip .pipe cache/n/v/package.tgz
+6. cb(null, package data, p)
+
+add a local tgz:
+1. pipe tgz through Unzip
+2. addTarStream(Unzip, tgz)
+
+add a local tar:
+1. pipe tar through Gzip
+2. addTarStream(tar, Gzip)
+
+addTarStream s, zipped
+1. buffer s bytes
+2. buffer zipped bytes
+3. pipe s through tar.Parse
+4. wait for package.json file entry
+5. parse for package.json data to find name & version
+6. unpipe Parser
+7. unpipe buffer
+8. pipe s to tar.Extract(cache/name/version/package/)
+9. pipe zipped to cache/name/version/package.tgz
+10. cb(null, data, s)
+11. re-emit buffered bytes
+
+
+# Higher level registry requests etc.
+
+add a name@version:
1. registry.get(name, version)
-2. if response isn't 304, add url(dist.tarball)
+2. if response isn't 304,
+ add registry url(dist.tarball, data, shasum)
-adding a name@range:
+add a name@range:
1. registry.get(name)
2. Find a version that satisfies
3. add name@version
-adding a local tarball:
-1. untar to tmp/random/{blah}
-2. goto folder(2)
+
+read(n, v)
+1. If n/v in cache, return package.json data, tgz stream
+2. add(n)
+3. return package.json data, tgz stream
+
+unpack(n, v, folder)
+1. [data, stream] = read(n, v)
+2. extract stream to folder
+
*/
exports = module.exports = cache
Please sign in to comment.
Something went wrong with that request. Please try again.