sane-wasm 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/libsane.js CHANGED
@@ -138,7 +138,7 @@ Module["ready"] = new Promise((resolve, reject) => {
138
138
  sane_control_option_set_value: true,
139
139
  sane_control_option_set_auto: true,
140
140
  sane_get_parameters: false,
141
- sane_start: false,
141
+ sane_start: true,
142
142
  sane_read: true,
143
143
  sane_cancel: true,
144
144
  sane_strstatus: false
Binary file
package/dist/index.d.ts CHANGED
@@ -371,9 +371,9 @@ export interface LibSANE {
371
371
  * Equivalent to the SANE API C function `sane_start`.
372
372
  * @see {@link https://sane-project.gitlab.io/standard/1.06/api.html#sane-start}
373
373
  */
374
- sane_start: () => {
374
+ sane_start: () => Promise<{
375
375
  status: SANEStatus;
376
- };
376
+ }>;
377
377
  /**
378
378
  * Equivalent to the SANE API C function `sane_read`.
379
379
  * @see {@link https://sane-project.gitlab.io/standard/1.06/api.html#sane-read}
package/dist/readers.d.ts CHANGED
@@ -52,7 +52,7 @@ export declare class ScanDataReader<T extends ScanDataReaderEventMap = ScanDataR
52
52
  /**
53
53
  * Start scanning operation.
54
54
  */
55
- start(): {
55
+ start(): Promise<{
56
56
  status: SANEStatus.UNSUPPORTED | SANEStatus.CANCELLED | SANEStatus.DEVICE_BUSY | SANEStatus.INVAL | SANEStatus.EOF | SANEStatus.JAMMED | SANEStatus.NO_DOCS | SANEStatus.COVER_OPEN | SANEStatus.IO_ERROR | SANEStatus.NO_MEM | SANEStatus.ACCESS_DENIED;
57
57
  parameters: null;
58
58
  promise: Promise<void>;
@@ -60,7 +60,7 @@ export declare class ScanDataReader<T extends ScanDataReaderEventMap = ScanDataR
60
60
  status: SANEStatus.GOOD;
61
61
  parameters: SANEParameters;
62
62
  promise: Promise<void>;
63
- };
63
+ }>;
64
64
  /**
65
65
  * Cancel scanning operation.
66
66
  */
package/dist/readers.js CHANGED
@@ -136,48 +136,46 @@ class ScanDataReader extends EventBaseClass {
136
136
  * Start scanning operation.
137
137
  */
138
138
  start() {
139
- if (this._used) {
140
- // readers are single use
141
- return {
142
- status: _1.SANEStatus.INVAL,
143
- parameters: null,
144
- promise: Promise.reject(new Error("Scan readers cannot be reused.")),
145
- };
146
- }
147
- else {
148
- const { status } = this._lib.sane_start();
139
+ return __awaiter(this, void 0, void 0, function* () {
140
+ if (this._used) {
141
+ // readers are single use
142
+ throw new Error("Scan readers cannot be reused.");
143
+ }
144
+ else {
145
+ const { status } = yield this._lib.sane_start();
146
+ if (status !== _1.SANEStatus.GOOD) {
147
+ return {
148
+ status,
149
+ parameters: null,
150
+ promise: Promise.reject(new Error(`Status ${_1.SANEStatus[status]} during sane_start().`)),
151
+ };
152
+ }
153
+ this._used = true;
154
+ }
155
+ // after successful start, sane_cancel needs to be called and we need
156
+ // to wait for sane_read, so subsequent fails need to use this._killed
157
+ // and run the read loop
158
+ const { status, parameters } = this._lib.sane_get_parameters();
149
159
  if (status !== _1.SANEStatus.GOOD) {
160
+ this._killed = new Error(`Status ${_1.SANEStatus[status]} during sane_get_parameters().`);
150
161
  return {
151
- status,
152
- parameters: null,
153
- promise: Promise.reject(new Error(`Status ${_1.SANEStatus[status]} during sane_start().`)),
162
+ status, parameters,
163
+ promise: this._readPromise(parameters),
154
164
  };
155
165
  }
156
- this._used = true;
157
- }
158
- // after successful start, sane_cancel needs to be called and we need
159
- // to wait for sane_read, so subsequent fails need to use this._killed
160
- // and run the read loop
161
- const { status, parameters } = this._lib.sane_get_parameters();
162
- if (status !== _1.SANEStatus.GOOD) {
163
- this._killed = new Error(`Status ${_1.SANEStatus[status]} during sane_get_parameters().`);
166
+ try {
167
+ this.fire('start', parameters);
168
+ }
169
+ catch (e) {
170
+ this._killed = e instanceof Error ? e : new Error("Unknown error while starting the scan.");
171
+ }
164
172
  return {
165
173
  status, parameters,
166
- promise: this._readPromise(parameters),
174
+ promise: this._readPromise(parameters).finally(() => {
175
+ this.fire('stop', parameters, this._killed instanceof Error ? this._killed : null);
176
+ }),
167
177
  };
168
- }
169
- try {
170
- this.fire('start', parameters);
171
- }
172
- catch (e) {
173
- this._killed = e instanceof Error ? e : new Error("Unknown error while starting the scan.");
174
- }
175
- return {
176
- status, parameters,
177
- promise: this._readPromise(parameters).finally(() => {
178
- this.fire('stop', parameters, this._killed instanceof Error ? this._killed : null);
179
- }),
180
- };
178
+ });
181
179
  }
182
180
  /**
183
181
  * Cancel scanning operation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sane-wasm",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "A project to bring the SANE API to the web.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",