Skip to content

Commit 182450c

Browse files
removed edits to Binary constructor
1 parent ffaf192 commit 182450c

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

src/binary.ts

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class Binary {
7373
* @param buffer - a buffer object containing the binary data.
7474
* @param subType - the option binary type.
7575
*/
76-
constructor(buffer?: string | BinarySequence | Binary, subType?: number) {
76+
constructor(buffer?: string | BinarySequence, subType?: number) {
7777
if (!(this instanceof Binary)) return new Binary(buffer, subType);
7878

7979
if (
@@ -88,32 +88,26 @@ export class Binary {
8888
);
8989
}
9090

91-
if (buffer != null && (buffer as Binary)._bsontype === 'Binary') {
92-
this.sub_type = (buffer as Binary).sub_type;
93-
this.buffer = (buffer as Binary).buffer;
94-
this.position = (buffer as Binary).position;
95-
} else {
96-
this.sub_type = subType ?? Binary.BSON_BINARY_SUBTYPE_DEFAULT;
91+
this.sub_type = subType ?? Binary.BSON_BINARY_SUBTYPE_DEFAULT;
9792

98-
if (buffer == null) {
99-
// create an empty binary buffer
100-
this.buffer = Buffer.alloc(Binary.BUFFER_SIZE);
101-
this.position = 0;
93+
if (buffer == null) {
94+
// create an empty binary buffer
95+
this.buffer = Buffer.alloc(Binary.BUFFER_SIZE);
96+
this.position = 0;
97+
} else {
98+
if (typeof buffer === 'string') {
99+
// string
100+
this.buffer = Buffer.from(buffer, 'binary');
101+
} else if (Array.isArray(buffer)) {
102+
// number[]
103+
this.buffer = Buffer.from(buffer);
102104
} else {
103-
if (typeof buffer === 'string') {
104-
// string
105-
this.buffer = Buffer.from(buffer, 'binary');
106-
} else if (Array.isArray(buffer)) {
107-
// number[]
108-
this.buffer = Buffer.from(buffer);
109-
} else {
110-
// Buffer | TypedArray | ArrayBuffer
111-
this.buffer = ensureBuffer(buffer);
112-
}
113-
114-
this.position = this.buffer.byteLength;
105+
// Buffer | TypedArray | ArrayBuffer
106+
this.buffer = ensureBuffer(buffer);
115107
}
116-
}
108+
109+
this.position = this.buffer.byteLength;
110+
117111
}
118112

119113
/**

0 commit comments

Comments
 (0)