phargo

package module
v0.0.0-...-ebc485a Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2018 License: MIT Imports: 15 Imported by: 0

README

PHARGO

PHAR-files reader and parser written in golang

Info

Parser supports several signature algorithms:

  • MD5
  • SHA1
  • SHA256
  • SHA512
  • OPENSSL

Also supports compression formats:

  • None
  • GZ
  • BZ2

Can read manifest version, alias and metadata. For every file inside PHAR-archive can read it contents, name, timestamp and metadata. Checks file CRC and signature of entire archive.

Installation

  1. Download and install:
$ go get -u github.com/deadkrolik/phargo
  1. Import and use it:
package main

import (
    "log"
    "time"

    "github.com/deadkrolik/phargo"
)

func main() {
    r := phargo.NewReader()
    
    //some limitations
    if false {
        r.SetOptions(phargo.Options{
            //metadata of every file and entire archive can be more than that number
            MaxMetaDataLength: 10000,
            //max length of first block of archive when looking for "HALT_COMPILER" string 
            MaxManifestLength: 1048576 * 100,
            //max length of name of the file
            MaxFileNameLength: 1000,
            //max length of archive alias in manifest
            MaxAliasLength: 1000,
        })
    }
    
    file, err := r.Parse("file.phar")
    if err != nil {
        log.Println(err)
        return
    }
    
    log.Println("Manifest version: ", file.Version)
    log.Println("File alias: ", file.Alias)
    log.Println("Serialized metadata: ", string(file.Metadata))
    
    for _, f := range file.Files {
        log.Println("File name: ", f.Name)
        log.Println("File metadata: ", string(f.Metadata))
        log.Println("File data len: ", len(f.Data))
        log.Println("File date: ", time.Unix(f.Timestamp, 0).String())
        log.Println("---")
    }
}

Running the tests

Just run the command:

$ go test

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Version  string
	Alias    string
	Metadata []byte
	Files    []PHARFile
}

File - parsed PHAR-file

type Options

type Options struct {
	MaxMetaDataLength uint32
	MaxManifestLength int64
	MaxFileNameLength uint32
	MaxAliasLength    uint32
}

Options - parser options

type PHARFile

type PHARFile struct {
	Name      string
	Timestamp int64
	Metadata  []byte
	Data      []byte
}

PHARFile - file inside PHAR-archive

type Reader

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

Reader - PHAR file parser

func NewReader

func NewReader() *Reader

NewReader - creates parser with default options

func (*Reader) Parse

func (r *Reader) Parse(filename string) (File, error)

Parse - start parsing PHAR file

func (*Reader) SetOptions

func (r *Reader) SetOptions(o Options)

SetOptions - applies options to parser

Jump to

Keyboard shortcuts

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