cdc

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2016 License: BSD-3-Clause Imports: 11 Imported by: 0

README

cdc GoDoc

Package cdc provides support for reading Chromium disk cache v2.

Usage

See the example_test.go for a basic example.

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("testcache")
	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 ErrBadAddr = errors.New("addr is not initialized")

ErrBadAddr is returned if the addr is not initialized.

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

ErrNotFound is returned when an entry is not found in cache.

Functions

This section is empty.

Types

type CacheAddr

type CacheAddr uint32

CacheAddr defines a storage address for a cache record.

func (CacheAddr) BlockSize

func (addr CacheAddr) BlockSize() uint32

BlockSize returns the block size.

func (CacheAddr) FileName

func (addr CacheAddr) FileName() (name string)

FileName returns the file name.

func (CacheAddr) FileNumber

func (addr CacheAddr) FileNumber() uint32

FileNumber returns the file number.

func (CacheAddr) FileType

func (addr CacheAddr) FileType() uint32

FileType returns one of these values:

EXTERNAL = 0,
RANKINGS = 1,
BLOCK_256 = 2,
BLOCK_1K = 3,
BLOCK_4K = 4,
BLOCK_FILES = 5,
BLOCK_ENTRIES = 6,
BLOCK_EVICTED = 7

func (CacheAddr) Initialized

func (addr CacheAddr) Initialized() bool

Initialized returns the initialization state.

func (CacheAddr) NumBlocks

func (addr CacheAddr) NumBlocks() uint32

NumBlocks returns the number of blocks.

func (CacheAddr) SeparateFile

func (addr CacheAddr) SeparateFile() bool

SeparateFile returns true if the cache record is located in a separated file.

func (CacheAddr) StartBlock

func (addr CacheAddr) StartBlock() uint32

StartBlock returns the start block.

type DiskCache

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

DiskCache reads the blocks files and maps URL to CacheAddr.

func OpenCache

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

OpenCache opens the disk cache at dir.

func (DiskCache) GetAddr

func (cache DiskCache) GetAddr(url string) CacheAddr

GetAddr returns the addr for url. The returned CacheAddr might not be initialized, meaning that the url is unknown.

func (DiskCache) OpenURL

func (cache DiskCache) OpenURL(url string) (*Entry, error)

OpenURL returns the Entry for url.

func (DiskCache) URLs

func (cache DiskCache) URLs() []string

URLs returns all the URLs currently stored.

type Entry

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

Entry represents a cache record as stored in the disk cache.

func OpenEntry

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

OpenEntry returns the Entry at addr, in the disk cache at dir.

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
Package cdc helps reading disk cache on command line.
Package cdc helps reading disk cache on command line.
webapp command
Package webapp helps browsing disk cache.
Package webapp helps browsing disk cache.

Jump to

Keyboard shortcuts

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