simplecache

package module
v2.0.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2017 License: BSD-3-Clause Imports: 13 Imported by: 0

README

simplecache GoDoc

The simplecache package provides support for reading Chromium simple cache v6 or v7.

Learn more: http://www.chromium.org/developers/design-documents/network-stack/disk-cache/very-simple-backend

See the example_test.go for an example of how to read an image from cache in testdata.

This project also includes a tool to read the cache from command line, read this README.

Short cache format

The simple cache contains different files:

Filename Description
index Fake index file
#####_0 Data stream file
#####_1 Data stream file
#####_s Data stream file
index-dir/the-real-index The real index file
Fake index file format (index)
offset size value description
0 8 0x656e74657220796f Magic
8 4 7 Version
12 8 0x0 Padding
Real index file format (the-real-index)

Overview:

  • File header
  • Last write reason (starting v7)
  • Index table
  • Last modified
File header

The index file header (struct indexHeader) is 36 bytes in size and consists of:

offset size value description
0 4 Payload size
4 4 Payload CRC32
8 8 0x656e74657220796f Magic
16 4 7 Version
20 8 Number of entries
28 8 Cache size
Index table

The index table is an array of entries. An entry (struct indexEntry) is 24 bytes in size and consists of:

offset size value description
0 8 Hash
8 8 Last used
16 8 Size
Data stream file format (#####_0)

Overview:

  • File header
  • URL
  • Data stream (stream 1)
  • Stream EOF
  • HTTP headers (stream 0)
  • (optionally) the SHA256 of the URL
  • Stream EOF
File header

The index file header (struct entryHeader) is 20 bytes in size and consists of:

offset size value description
0 8 0xfcfb6d1ba7725c30 Magic
8 4 5 Version
12 4 URL length
16 4 URL MD5
Stream EOF

The separator (struct entryEOF) contains information about the stream above. It is 20 bytes in size and consists of:

offset size value description
0 8 0xf4fa6f45970d41d8 Magic
8 4 Flag
12 4 stream CRC32
16 4 stream size
Flag
value description
0
1 the stream has CRC32
2 the URL has SHA256
3 1 + 2
Data stream file format (#####_1)

Overview:

  • File header
  • URL
  • Data stream (stream 2)
  • Stream EOF
Data stream file format (#####_s)

Overview:

  • File header
  • many of the following:
    • Range header
    • Range data stream
File header

The index file header (struct entryHeader) is 20 bytes in size and consists of:

offset size value description
0 8 0xfcfb6d1ba7725c30 Magic
8 4 7 Version
12 4 URL length
16 4 URL MD5
Range header

The range header (struct sparseRangeHeader) contains information about the following range stream. It is 28 bytes in size and consists of:

offset size value description
0 8 0xeb97bf016553676b Magic
8 8 stream offset
16 8 stream size
24 4 stream CRC32

Documentation

Overview

Package simplecache provides support for reading Chromium simple cache. http://www.chromium.org/developers/design-documents/network-stack/disk-cache/very-simple-backend

Example

Example gets an entry from the cache and prints it to stdout.

package main

import (
	"fmt"
	"image/png"
	"log"

	"github.com/schorlet/simplecache"
)

func main() {
	entry, err := simplecache.Get("https://golang.org/doc/gopher/pkg.png", "testdata")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(entry.URL)

	header, err := entry.Header()
	if err != nil {
		log.Fatal(err)
	}
	for _, key := range []string{"Status", "Content-Length", "Content-Type"} {
		fmt.Printf("%s: %s\n", key, header.Get(key))
	}

	body, err := entry.Body()
	if err != nil {
		log.Fatal(err)
	}
	defer body.Close()

	config, err := png.DecodeConfig(body)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("PNG image data, %d x %d\n", config.Width, config.Height)

}
Output:

https://golang.org/doc/gopher/pkg.png
Status: 200
Content-Length: 5409
Content-Type: image/png
PNG image data, 83 x 120

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func URLs

func URLs(path string) ([]string, error)

URLs returns all the URLs currently stored in the cache.

On linux, valid cache paths are:

~/.cache/chromium/Default/Cache
~/.cache/chromium/Default/Media Cache

URLs reads the files named "path/index" and "path/index-dir/the-real-index" and every entry files named "path/hash(url)_0" where hash is read from the-real-index file.

An error is returned if the format of the index files is unexpected.

Types

type Entry

type Entry struct {
	URL string
	// contains filtered or unexported fields
}

Entry represents a HTTP response as stored in the cache. Each entry is stored in a file named "path/hash(url)_0".

func Get

func Get(url, path string) (*Entry, error)

Get returns the Entry for the specified URL. An error is returned if the format of the entry does not match the one expected.

func (*Entry) Body

func (e *Entry) Body() (io.ReadCloser, error)

Body returns the HTTP body. Body may read a file named "path/hash(url)_s".

func (*Entry) Header

func (e *Entry) Header() (http.Header, error)

Header returns the HTTP header.

Directories

Path Synopsis
cmd
simplecache
Command simplecache helps reading chromium simple cache v6 or v7.
Command simplecache helps reading chromium simple cache v6 or v7.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL