Skip to content

Commit 87abdcc

Browse files
committed
Fix #849
1 parent d568466 commit 87abdcc

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

pkg/api/api.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ func ReadAndValidate(rs io.ReadSeeker, conf *model.Configuration) (ctx *model.Co
155155
return ctx, nil
156156
}
157157

158+
func cmdAssumingOptimization(cmd model.CommandMode) bool {
159+
return cmd == model.OPTIMIZE ||
160+
cmd == model.FILLFORMFIELDS ||
161+
cmd == model.RESETFORMFIELDS ||
162+
cmd == model.LISTIMAGES ||
163+
cmd == model.EXTRACTIMAGES ||
164+
cmd == model.EXTRACTFONTS
165+
}
166+
158167
// ReadValidateAndOptimize returns an optimized model.Context of rs ready for processing a specific command.
159168
// conf.Cmd is expected to be configured properly.
160169
func ReadValidateAndOptimize(rs io.ReadSeeker, conf *model.Configuration) (ctx *model.Context, err error) {
@@ -167,9 +176,10 @@ func ReadValidateAndOptimize(rs io.ReadSeeker, conf *model.Configuration) (ctx *
167176
return nil, err
168177
}
169178

170-
// With the exception of the OPTIMIZE command optimization of the cross reference table is optional but usually recommended.
171-
// For large or complex files it may make sense to skip optimization.
172-
if conf.Cmd == model.OPTIMIZE || conf.Optimize {
179+
// With the exception of commands utilizing structs provided the Optimize step
180+
// command optimization of the cross reference table is optional but usually recommended.
181+
// For large or complex files it may make sense to skip optimization and set conf.Optimize = false.
182+
if cmdAssumingOptimization(conf.Cmd) || conf.Optimize {
173183
if err = OptimizeContext(ctx); err != nil {
174184
return nil, err
175185
}

0 commit comments

Comments
 (0)