Skip to content

Commit

Permalink
Remove all synchronous methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yushulx committed Dec 26, 2024
1 parent 8e1a0ff commit 735051d
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 317 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ The Node.js barcode QR code SDK is implemented by wrapping [Dynamsoft Barcode Re
- `decodeBufferAsync(buffer: any, width: number, height: number, stride: number, format: formats, callback?: (err: Error | null, result?: BarcodeResult[]) => void, template?: string): void`
- `decodeBufferAsync(buffer: any, width: number, height: number, stride: number, format: formats, template?: string): Promise<BarcodeResult[]>`
**Synchronous Methods**
- `decodeFile(filePath: string, format: formats, template?: string): BarcodeResult[]`
- `decodeFileStream(stream: any, length: number, format: formats, template?: string): BarcodeResult[]`
- `decodeBase64(base64String: string, format: formats, template?: string): BarcodeResult[]`
- `decodeYUYV(data: any, width: number, height: number, format: formats, template?: string): BarcodeResult[]`
- `decodeBuffer(buffer: any, width: number, height: number, stride: number, format: formats, template?: string): BarcodeResult[]`
## Template Usage
1. Visit the [barcode reader online demo](https://demo.dynamsoft.com/barcode-reader-v9/).
2. Customize parameters in advanced settings and then download the template.
Expand Down
18 changes: 0 additions & 18 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,6 @@ export interface BarcodeReader {
decodeBufferAsync(buffer: any, width: number, height: number, stride: number, format: formats, callback?: (err: Error | null, result?: BarcodeResult[]) => void, template?: string): void;
decodeBufferAsync(buffer: any, width: number, height: number, stride: number, format: formats, template?: string): Promise<BarcodeResult[]>;
destroyInstance(): void;

decodeFile(filePath: string, format: formats, callback?: (err: Error | null, result?: BarcodeResult[]) => void, template?: string): void;
decodeFile(filePath: string, format: formats, template?: string): BarcodeResult[];
decodeFileStream(stream: any, length: number, format: formats, callback?: (err: Error | null, result?: BarcodeResult[]) => void, template?: string): void;
decodeFileStream(stream: any, length: number, format: formats, template?: string): BarcodeResult[];
decodeBase64(base64String: string, format: formats, callback: (err: Error | null, result?: BarcodeResult[]) => void, template?: string): void;
decodeBase64(base64String: string, format: formats, template?: string): BarcodeResult[];
decodeYUYV(data: any, width: number, height: number, format: formats, callback?: (err: Error | null, result?: BarcodeResult[]) => void, template?: string): void;
decodeYUYV(data: any, width: number, height: number, format: formats, template?: string): BarcodeResult[];
decodeBuffer(buffer: any, width: number, height: number, stride: number, format: formats, callback?: (err: Error | null, result?: BarcodeResult[]) => void, template?: string): void;
decodeBuffer(buffer: any, width: number, height: number, stride: number, format: formats, template?: string): BarcodeResult[];
}

export function getVersion(): string;
Expand All @@ -108,10 +97,3 @@ export function decodeYUYVAsync(data: any, width: number, height: number, format
export function decodeYUYVAsync(data: any, width: number, height: number, format: formats, template?: string): Promise<BarcodeResult[]>;
export function decodeBufferAsync(buffer: any, width: number, height: number, stride: number, format: formats, callback?: (err: Error | null, result?: BarcodeResult[]) => void, template?: string): void;
export function decodeBufferAsync(buffer: any, width: number, height: number, stride: number, format: formats, template?: string): Promise<BarcodeResult[]>;

// Synchronous API
export function decodeFile(filePath: string, format: formats, template?: string): BarcodeResult[];
export function decodeFileStream(stream: any, length: number, format: formats, template?: string): BarcodeResult[];
export function decodeBase64(base64String: string, format: formats, template?: string): BarcodeResult[];
export function decodeYUYV(data: any, width: number, height: number, format: formats, template?: string): BarcodeResult[];
export function decodeBuffer(buffer: any, width: number, height: number, stride: number, format: formats, template?: string): BarcodeResult[];
268 changes: 134 additions & 134 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,33 @@ module.exports = {
return promise;
}
},
decodeFile: function () {
var callback = arguments[2];
var template = "";
if (callback && typeof callback === 'function') {
template = arguments[3];
}
else {
template = arguments[2];
}
checkBarcodeReader();
let result;
let error;
barcodeReader.decodeFile(arguments[0], arguments[1], function (err, msg) {
result = msg;
error = err;
}, template);
// decodeFile: function () {
// var callback = arguments[2];
// var template = "";
// if (callback && typeof callback === 'function') {
// template = arguments[3];
// }
// else {
// template = arguments[2];
// }
// checkBarcodeReader();
// let result;
// let error;
// barcodeReader.decodeFile(arguments[0], arguments[1], function (err, msg) {
// result = msg;
// error = err;
// }, template);

if (callback && typeof callback === 'function') {
if (error) {
callback(error);
} else {
callback(null, result);
}
} else {
return result;
}
},
// if (callback && typeof callback === 'function') {
// if (error) {
// callback(error);
// } else {
// callback(null, result);
// }
// } else {
// return result;
// }
// },
decodeFileStreamAsync: function () {
var callback = arguments[3];
var template = "";
Expand Down Expand Up @@ -149,35 +149,35 @@ module.exports = {
return promise;
}
},
decodeFileStream: function () {
var callback = arguments[3];
var template = "";
if (callback && typeof callback === 'function') {
template = arguments[4];
}
else {
template = arguments[3];
}
// decodeFileStream: function () {
// var callback = arguments[3];
// var template = "";
// if (callback && typeof callback === 'function') {
// template = arguments[4];
// }
// else {
// template = arguments[3];
// }

checkBarcodeReader();
let result;
let error;
barcodeReader.decodeFileStream(arguments[0], arguments[1], arguments[2], function (err, msg) {
result = msg;
error = err;
}, template);
// checkBarcodeReader();
// let result;
// let error;
// barcodeReader.decodeFileStream(arguments[0], arguments[1], arguments[2], function (err, msg) {
// result = msg;
// error = err;
// }, template);

if (callback && typeof callback === 'function') {
if (error) {
callback(error);
} else {
callback(null, result);
}
}
else {
return result;
}
},
// if (callback && typeof callback === 'function') {
// if (error) {
// callback(error);
// } else {
// callback(null, result);
// }
// }
// else {
// return result;
// }
// },
decodeBase64Async: function () {
var callback = arguments[2];
var template = "";
Expand Down Expand Up @@ -209,35 +209,35 @@ module.exports = {
return promise;
}
},
decodeBase64: function () {
var callback = arguments[2];
var template = "";
if (callback && typeof callback === 'function') {
template = arguments[3];
}
else {
template = arguments[2];
}
// decodeBase64: function () {
// var callback = arguments[2];
// var template = "";
// if (callback && typeof callback === 'function') {
// template = arguments[3];
// }
// else {
// template = arguments[2];
// }

checkBarcodeReader();
let result;
let error;
barcodeReader.decodeBase64(arguments[0], arguments[1], function (err, msg) {
result = msg;
error = err;
}, template);
// checkBarcodeReader();
// let result;
// let error;
// barcodeReader.decodeBase64(arguments[0], arguments[1], function (err, msg) {
// result = msg;
// error = err;
// }, template);

if (callback && typeof callback === 'function') {
if (error) {
callback(error);
} else {
callback(null, result);
}
}
else {
return result;
}
},
// if (callback && typeof callback === 'function') {
// if (error) {
// callback(error);
// } else {
// callback(null, result);
// }
// }
// else {
// return result;
// }
// },
decodeYUYVAsync: function () {
var callback = arguments[4];
var template = "";
Expand Down Expand Up @@ -268,35 +268,35 @@ module.exports = {
return promise;
}
},
decodeYUYV: function () {
var callback = arguments[4];
var template = "";
if (callback && typeof callback === 'function') {
template = arguments[5];
}
else {
template = arguments[4];
}
// decodeYUYV: function () {
// var callback = arguments[4];
// var template = "";
// if (callback && typeof callback === 'function') {
// template = arguments[5];
// }
// else {
// template = arguments[4];
// }

checkBarcodeReader();
let result;
let error;
barcodeReader.decodeYUYV(arguments[0], arguments[1], arguments[2], arguments[3], function (err, msg) {
result = msg;
error = err;
}, template);
// checkBarcodeReader();
// let result;
// let error;
// barcodeReader.decodeYUYV(arguments[0], arguments[1], arguments[2], arguments[3], function (err, msg) {
// result = msg;
// error = err;
// }, template);

if (callback && typeof callback === 'function') {
if (error) {
callback(error);
} else {
callback(null, result);
}
}
else {
return result;
}
},
// if (callback && typeof callback === 'function') {
// if (error) {
// callback(error);
// } else {
// callback(null, result);
// }
// }
// else {
// return result;
// }
// },
decodeBufferAsync: function () {
var callback = arguments[5];
var template = "";
Expand Down Expand Up @@ -327,35 +327,35 @@ module.exports = {
return promise;
}
},
decodeBuffer: function () {
var callback = arguments[5];
var template = "";
if (callback && typeof callback === 'function') {
template = arguments[6];
}
else {
template = arguments[5];
}
// decodeBuffer: function () {
// var callback = arguments[5];
// var template = "";
// if (callback && typeof callback === 'function') {
// template = arguments[6];
// }
// else {
// template = arguments[5];
// }

checkBarcodeReader();
let result;
let error;
barcodeReader.decodeBuffer(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], function (err, msg) {
result = msg;
error = err;
}, template);
// checkBarcodeReader();
// let result;
// let error;
// barcodeReader.decodeBuffer(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], function (err, msg) {
// result = msg;
// error = err;
// }, template);

if (callback && typeof callback === 'function') {
if (error) {
callback(error);
} else {
callback(null, result);
}
}
else {
return result;
}
},
// if (callback && typeof callback === 'function') {
// if (error) {
// callback(error);
// } else {
// callback(null, result);
// }
// }
// else {
// return result;
// }
// },
formats: formats,
barcodeTypes: barcodeTypes,
getVersion: dbr.getVersionNumber,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "barcode4nodejs",
"version": "10.0.4",
"version": "10.0.5",
"description": "Node.js bindings to Dynamsoft Barcode Reader C/C++ SDK.",
"keywords": [
"barcode",
Expand Down
Loading

0 comments on commit 735051d

Please sign in to comment.