Write aggregates all accumulated data by category and writes each non-empty category to its own file (e.g. password.csv, cookie.json).
()
| 57 | // Write aggregates all accumulated data by category and writes each |
| 58 | // non-empty category to its own file (e.g. password.csv, cookie.json). |
| 59 | func (o *Writer) Write() error { |
| 60 | if err := os.MkdirAll(o.dir, 0o750); err != nil { |
| 61 | return fmt.Errorf("create output dir: %w", err) |
| 62 | } |
| 63 | agg := o.aggregate() |
| 64 | for _, cs := range agg { |
| 65 | if err := o.writeFile(cs.name, cs.rows); err != nil { |
| 66 | return err |
| 67 | } |
| 68 | } |
| 69 | if len(agg) > 0 { |
| 70 | fmt.Fprintln(os.Stderr) |
| 71 | log.Infof("Exported to %s/", o.dir) |
| 72 | for _, cs := range agg { |
| 73 | filename := fmt.Sprintf("%s.%s", cs.name, o.formatter.ext()) |
| 74 | log.Infof(" %-24s %d entries", filename, len(cs.rows)) |
| 75 | } |
| 76 | } |
| 77 | return nil |
| 78 | } |
| 79 | |
| 80 | // categoryRows holds one category's aggregated rows for writing. |
| 81 | type categoryRows struct { |