cdc

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: 11 Imported by: 0

README

cdc GoDoc

The cdc package provides support for reading Chromium disk cache v2.

The disk cache stores resources fetched from the web so that they can be accessed quickly at a latter time if needed.

Learn more:

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.

Documentation

Overview

Package cdc provides support for reading Chromium disk cache v2. https://www.chromium.org/developers/design-documents/network-stack/disk-cache

Example

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

package main

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

	"github.com/schorlet/cdc"
)

func main() {
	cache, err := cdc.OpenCache("testdata")
	if err != nil {
		log.Fatal(err)
	}

	entry, err := cache.OpenURL("https://golang.org/doc/gopher/pkg.png")
	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

View Source
var ErrNotFound = errors.New("entry not found")

ErrNotFound is returned if the entry is not found.

Functions

This section is empty.

Types

type Addr

type Addr uint32

Addr defines a storage address for an Entry.

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache gives read access to the chromium disk cache.

The cache is composed of one "index" file, four or more "data_[0-9]" files and many of "f_[0-9]+" separate files.

Learn more: http://www.forensicswiki.org/wiki/Google_Chrome#Disk_Cache http://www.forensicswiki.org/wiki/Chrome_Disk_Cache_Format

func OpenCache

func OpenCache(dir string) (*Cache, error)

OpenCache opens the cache in dir. Opens the "index" file to read the addresses and then opens each Entry to read the URL and associate it to an address.

func (*Cache) GetAddr

func (c *Cache) GetAddr(url string) (Addr, error)

GetAddr returns the address of the URL. An error is returned if the URL is not found.

func (*Cache) OpenURL

func (c *Cache) OpenURL(url string) (*Entry, error)

OpenURL returns the Entry for the specified URL. An error is returned if the URL is not found.

func (*Cache) URLs

func (c *Cache) URLs() []string

URLs returns all the URLs currently stored.

type Entry

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

Entry represents a HTTP response as stored in the cache. An Entry is stored in one of the "data_[0-9]" files or in a "f_[0-9]+" separate file.

func OpenEntry

func OpenEntry(addr Addr, dir string) (*Entry, error)

OpenEntry returns the Entry at the specified address.

func (*Entry) Body

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

Body returns the HTTP body.

func (*Entry) Header

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

Header returns the HTTP header.

func (*Entry) URL

func (e *Entry) URL() string

URL returns the entry URL.

Directories

Path Synopsis
cmd
cdc
Command cdc helps reading disk cache from command line.
Command cdc helps reading disk cache from command line.
webapp
Command webapp helps browsing disk cache.
Command webapp helps browsing disk cache.

Jump to

Keyboard shortcuts

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