Skip to content

Commit

Permalink
Add maxBuffer option (#73)
Browse files Browse the repository at this point in the history
This allows the ability to exceed the default 1024 * 1024 buffer size
for stdout/stderr.

wavded/ogre#97
  • Loading branch information
wavded authored Aug 3, 2021
1 parent 47e72c5 commit b5f64fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface Options {
destination?: string
env?: Record<string, string>
timeout?: number
maxBuffer?: number
}

// Known /vsistdout/ support.
Expand All @@ -44,7 +45,8 @@ class Ogr2ogr implements PromiseLike<Result> {
private customOptions?: string[]
private customDestination?: string
private customEnv?: Record<string, string>
private timeout?: number
private timeout: number
private maxBuffer: number

constructor(input: Input, opts: Options = {}) {
this.inputPath = vsiStdIn
Expand All @@ -53,7 +55,8 @@ class Ogr2ogr implements PromiseLike<Result> {
this.customOptions = opts.options
this.customDestination = opts.destination
this.customEnv = opts.env
this.timeout = opts.timeout
this.timeout = opts.timeout ?? 0
this.maxBuffer = opts.maxBuffer ?? 1024 * 1024 * 50

let {path, ext} = this.newOutputPath(this.outputFormat)
this.outputPath = path
Expand Down Expand Up @@ -152,13 +155,12 @@ class Ogr2ogr implements PromiseLike<Result> {
]
if (this.customOptions) args.push(...this.customOptions)
let env = this.customEnv ? {...process.env, ...this.customEnv} : undefined
let timeout = this.timeout ?? 0

let {stdout, stderr} = await new Promise<RunOutput>((res, rej) => {
let proc = execFile(
command,
args,
{env, timeout},
{env, timeout: this.timeout, maxBuffer: this.maxBuffer},
(err, stdout, stderr) => {
if (err) rej(err)
res({stdout, stderr})
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The following **`options`** are available (none required):

- `format` - Output format (default: `GeoJSON`)
- `timeout` - Timeout before command forcibly terminated (default: `0`)
- `maxBuffer` - Max output size in bytes for stdout/stderr (default: `1024 * 2014 * 50`)
- `options` - Custom [ogr2ogr arguments][4] and [driver options][5] (e.g. `['--config', 'SHAPE_RESTORE_SHX', 'TRUE']`)
- `env` - Custom environmental variables (e.g. `{ATTRIBUTES_SKIP: 'YES'}`)
- `destination` - Select another output than the **output** object (e.g. useful for writing to databases).
Expand Down

0 comments on commit b5f64fb

Please sign in to comment.