mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-12-04 05:43:27 +01:00
Later layers speak categories and records, and export needs nothing else. Ordering rows once in the exporter fixes Firefox history, written least visited first.
56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package export
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/moond4rk/hackbrowserdata/internal/category"
|
|
"github.com/moond4rk/hackbrowserdata/internal/record"
|
|
)
|
|
|
|
// The zero Format is JSON, the -f default.
|
|
type Format int
|
|
|
|
const (
|
|
JSON Format = iota
|
|
CSV
|
|
CookieEditor
|
|
)
|
|
|
|
func ParseFormat(s string) (Format, error) {
|
|
switch s {
|
|
case "json":
|
|
return JSON, nil
|
|
case "csv":
|
|
return CSV, nil
|
|
case "cookie-editor":
|
|
return CookieEditor, nil
|
|
default:
|
|
return 0, fmt.Errorf("unsupported format: %s", s)
|
|
}
|
|
}
|
|
|
|
func (f Format) ext() string {
|
|
if f == CSV {
|
|
return "csv"
|
|
}
|
|
return "json"
|
|
}
|
|
|
|
// encoder writes one category's file; it frames the document itself so that every Write can append to it.
|
|
type encoder interface {
|
|
encode(r record.Record) error
|
|
end() error
|
|
}
|
|
|
|
func newEncoder(w io.Writer, f Format, c category.Category) encoder {
|
|
switch {
|
|
case f == CSV:
|
|
return newCSVEncoder(w)
|
|
case f == CookieEditor && c == category.Cookie:
|
|
return &jsonEncoder{w: w, value: cookieEditorValue}
|
|
default:
|
|
return &jsonEncoder{w: w, escapeHTML: true}
|
|
}
|
|
}
|