8000 [pull] master from tdewolff:master by pull[bot] · Pull Request #303 · kokizzu/minify · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.25.0
require (
github.com/djherbis/atime v1.1.0
github.com/fsnotify/fsnotify v1.10.1
github.com/tdewolff/argp v0.0.0-20260424074207-decde4f86440
github.com/tdewolff/argp v0.0.0-20260809175504-e6e95971d4fb
github.com/tdewolff/parse/v2 v2.8.16
github.com/tdewolff/test v1.0.12
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/tdewolff/argp v0.0.0-20260424074207-decde4f86440 h1:wJfhggFlz8Y2aRDorOjgX6KuIzsDg/FjlIlK8Tg804I=
github.com/tdewolff/argp v0.0.0-20260424074207-decde4f86440/go.mod h1:t4IfmOfK1WpBPd456pTdSB4f+BuMp6CUGnV7CBzduxk=
github.com/tdewolff/argp v0.0.0-20260809175504-e6e95971d4fb h1:CYEGzpyPGyBBIAC6Ul0m/e4nMHnEuAwmYFYUfe8iUpk=
github.com/tdewolff/argp v0.0.0-20260809175504-e6e95971d4fb/go.mod h1:uuGOKudcV0l0+d8DjP4N6JrhRO78Bc13by6E6QSiPcA=
github.com/tdewolff/parse/v2 v2.8.15 h1:3/Psth16LHpsy2NS/7ShXDsoWt1x0f3tQMSbmQi+jO8=
github.com/tdewolff/parse/v2 v2.8.15/go.mod h1:XdsoSFThlVIRIajAuqz1evNY7bagZS8LBOPA3aVopwQ=
github.com/tdewolff/parse/v2 v2.8.16 h1:bLk5svUOQRkW/Y2SJ+DeENSIkZBcTIkq+Atyv5D8feI=
Expand Down
11 changes: 7 additions & 4 deletions minify.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"os/exec"
"path"
"regexp"
"slices"
"strings"
"sync"

Expand Down Expand Up @@ -243,8 +244,9 @@ func (m *M) MinifyMimetype(mimetype []byte, w io.Writer, r io.Reader, params map
// Bytes minifies an array of bytes (safe for concurrent use). When an error occurs it return the original array and the error.
// It returns an error when no such mimetype exists (ErrNotExist) or any error occurred in the minifier function.
func (m *M) Bytes(mediatype string, v []byte) ([]byte, error) {
out := buffer.NewWriter(make([]byte, 0, len(v)))
if err := m.Minify(mediatype, out, buffer.NewReader(v)); err != nil {
b := slices.Clone(v) // TODO: test
out := buffer.NewWriter(b[:0])
if err := m.Minify(mediatype, out, buffer.NewReader(b)); err != nil {
return v, err
}
return out.Bytes(), nil
Expand All @@ -253,8 +255,9 @@ func (m *M) Bytes(mediatype string, v []byte) ([]byte, error) {
// String minifies a string (safe for concurrent use). When a 654A n error occurs it return the original string and the error.
// It returns an error when no such mimetype exists (ErrNotExist) or any error occurred in the minifier function.
func (m *M) String(mediatype string, v string) (string, error) {
out := buffer.NewWriter(make([]byte, 0, len(v)))
if err := m.Minify(mediatype, out, buffer.NewReader([]byte(v))); err != nil {
b := []byte(v)
out := buffer.NewWriter(b[:0]) // TODO: test
if err := m.Minify(mediatype, out, buffer.NewReader(b)); err != nil {
return v, err
}
return string(out.Bytes()), nil
Expand Down
Loading
0