react-native-nitro-buffer 0.0.1 → 0.0.2

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/lib/Buffer.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export declare class Buffer extends Uint8Array {
2
+ static poolSize: number;
2
3
  constructor(length: number);
3
4
  constructor(array: Uint8Array);
4
5
  constructor(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number);
@@ -11,6 +12,7 @@ export declare class Buffer extends Uint8Array {
11
12
  static byteLength(string: string, encoding?: string): number;
12
13
  static isBuffer(obj: any): obj is Buffer;
13
14
  static compare(buf1: Uint8Array, buf2: Uint8Array): number;
15
+ equals(otherBuffer: Uint8Array): boolean;
14
16
  static copyBytesFrom(view: ArrayBufferView, offset?: number, length?: number): Buffer;
15
17
  static concat(list: Uint8Array[], totalLength?: number): Buffer;
16
18
  write(string: string, offset?: number, length?: number, encoding?: string): number;
@@ -70,7 +72,7 @@ export declare class Buffer extends Uint8Array {
70
72
  type: 'Buffer';
71
73
  data: number[];
72
74
  };
73
- static poolSize: number;
75
+ inspect(): string;
74
76
  static isEncoding(encoding: string): boolean;
75
77
  swap16(): Buffer;
76
78
  swap32(): Buffer;
package/lib/Buffer.js CHANGED
@@ -58,6 +58,9 @@ class Buffer extends Uint8Array {
58
58
  if (Array.isArray(value)) {
59
59
  return new Buffer(new Uint8Array(value).buffer);
60
60
  }
61
+ if (typeof value === 'object' && value !== null && value.type === 'Buffer' && Array.isArray(value.data)) {
62
+ return new Buffer(value.data);
63
+ }
61
64
  throw new TypeError('Unsupported type for Buffer.from');
62
65
  }
63
66
  static alloc(size, fill, encoding) {
@@ -91,6 +94,13 @@ class Buffer extends Uint8Array {
91
94
  static compare(buf1, buf2) {
92
95
  return getNative().compare(buf1.buffer, buf1.byteOffset, buf1.byteLength, buf2.buffer, buf2.byteOffset, buf2.byteLength);
93
96
  }
97
+ equals(otherBuffer) {
98
+ if (!Buffer.isBuffer(otherBuffer))
99
+ throw new TypeError('Argument must be a Buffer');
100
+ if (this === otherBuffer)
101
+ return true;
102
+ return Buffer.compare(this, otherBuffer) === 0;
103
+ }
94
104
  static copyBytesFrom(view, offset, length) {
95
105
  if (offset === undefined)
96
106
  offset = 0;
@@ -544,6 +554,22 @@ class Buffer extends Uint8Array {
544
554
  data: Array.from(this)
545
555
  };
546
556
  }
557
+ inspect() {
558
+ let str = '';
559
+ const max = 50; // Default max bytes to inspect
560
+ const len = Math.min(this.length, max);
561
+ for (let i = 0; i < len; i++) {
562
+ if (i > 0)
563
+ str += ' ';
564
+ str += this[i].toString(16).padStart(2, '0');
565
+ }
566
+ if (this.length > max)
567
+ str += ' ... ' + (this.length - max) + ' more bytes';
568
+ return '<Buffer ' + str + '>';
569
+ }
570
+ [Symbol.for('nodejs.util.inspect.custom')]() {
571
+ return this.inspect();
572
+ }
547
573
  static isEncoding(encoding) {
548
574
  switch (encoding.toLowerCase()) {
549
575
  case 'utf8':
package/package.json CHANGED
@@ -1,55 +1,50 @@
1
1
  {
2
- "name": "react-native-nitro-buffer",
3
- "version": "0.0.1",
4
- "description": "Node.js compatible buffer module for React Native",
5
- "main": "lib/index.js",
6
- "module": "lib/index.js",
7
- "types": "lib/index.d.ts",
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/iwater/react-native-nitro-buffer.git"
11
- },
12
- "homepage": "https://github.com/iwater/react-native-nitro-buffer",
13
- "scripts": {
14
- "build": "tsc",
15
- "test": "jest",
16
- "prepublishOnly": "npm run build"
17
- },
18
- "keywords": [
19
- "react-native",
20
- "ios",
21
- "android",
22
- "buffer",
23
- "node-buffer",
24
- "nitro"
25
- ],
26
- "author": "iwater <iwater@gmail.com>",
27
- "license": "ISC",
28
- "peerDependencies": {
29
- "react": "*",
30
- "react-native": "*",
31
- "react-native-nitro-modules": "*"
32
- },
33
- "devDependencies": {
34
- "@types/jest": "^30.0.0",
35
- "@types/node": "^18.19.130",
36
- "@types/react": "*",
37
- "jest": "^29.0.0",
38
- "react-native-nitro-modules": "*",
39
- "ts-jest": "^29.0.0",
40
- "typescript": "^5.0.0"
41
- },
42
- "dependencies": {
43
- "react-native-nitro-modules": "*"
44
- },
45
- "packageManager": "yarn@4.12.0",
46
- "files": [
47
- "lib/",
48
- "src/",
49
- "cpp/",
50
- "ios/",
51
- "android/",
52
- "nitrogen/",
53
- "*.podspec"
54
- ]
2
+ "name": "react-native-nitro-buffer",
3
+ "version": "0.0.2",
4
+ "description": "Node.js compatible buffer module for React Native",
5
+ "main": "lib/index.js",
6
+ "module": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "test": "jest",
11
+ "prepublishOnly": "npm run build"
12
+ },
13
+ "keywords": [
14
+ "react-native",
15
+ "ios",
16
+ "android",
17
+ "buffer",
18
+ "node-buffer",
19
+ "nitro"
20
+ ],
21
+ "author": "iwater <iwater@gmail.com>",
22
+ "license": "ISC",
23
+ "peerDependencies": {
24
+ "react": "*",
25
+ "react-native": "*",
26
+ "react-native-nitro-modules": "*"
27
+ },
28
+ "devDependencies": {
29
+ "@types/jest": "^30.0.0",
30
+ "@types/node": "^18.19.130",
31
+ "@types/react": "*",
32
+ "jest": "^29.0.0",
33
+ "react-native-nitro-modules": "*",
34
+ "ts-jest": "^29.0.0",
35
+ "typescript": "^5.0.0"
36
+ },
37
+ "dependencies": {
38
+ "react-native-nitro-modules": "*"
39
+ },
40
+ "packageManager": "yarn@4.12.0",
41
+ "files": [
42
+ "lib/",
43
+ "src/",
44
+ "cpp/",
45
+ "ios/",
46
+ "android/",
47
+ "nitrogen/",
48
+ "*.podspec"
49
+ ]
55
50
  }
@@ -6,12 +6,12 @@ Pod::Spec.new do |s|
6
6
  s.name = "react-native-nitro-buffer"
7
7
  s.version = package["version"]
8
8
  s.summary = package["description"]
9
- s.homepage = "https://github.com/iwater/react-native-nitro-buffer"
9
+ s.homepage = "https://github.com/iwater/rn-http-server"
10
10
  s.license = package["license"]
11
11
  s.authors = package["author"]
12
12
 
13
13
  s.platform = :ios, "13.0"
14
- s.source = { :git => "https://github.com/iwater/react-native-nitro-buffer.git", :tag => "v#{s.version}" }
14
+ s.source = { :git => "https://github.com/iwater/rn-http-server.git", :tag => "v#{s.version}" }
15
15
 
16
16
  s.source_files = [
17
17
  "ios/**/*.{h,m,mm,swift}",
package/src/Buffer.ts CHANGED
@@ -12,6 +12,8 @@ function getNative(): NitroBuffer {
12
12
  }
13
13
 
14
14
  export class Buffer extends Uint8Array {
15
+ static poolSize = 8192
16
+
15
17
  constructor(length: number)
16
18
  constructor(array: Uint8Array)
17
19
  constructor(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number)
@@ -59,6 +61,9 @@ export class Buffer extends Uint8Array {
59
61
  if (Array.isArray(value)) {
60
62
  return new Buffer(new Uint8Array(value).buffer)
61
63
  }
64
+ if (typeof value === 'object' && value !== null && value.type === 'Buffer' && Array.isArray(value.data)) {
65
+ return new Buffer(value.data)
66
+ }
62
67
  throw new TypeError('Unsupported type for Buffer.from')
63
68
  }
64
69
 
@@ -100,6 +105,12 @@ export class Buffer extends Uint8Array {
100
105
  return getNative().compare(buf1.buffer as ArrayBuffer, buf1.byteOffset, buf1.byteLength, buf2.buffer as ArrayBuffer, buf2.byteOffset, buf2.byteLength)
101
106
  }
102
107
 
108
+ equals(otherBuffer: Uint8Array): boolean {
109
+ if (!Buffer.isBuffer(otherBuffer)) throw new TypeError('Argument must be a Buffer')
110
+ if (this === otherBuffer) return true
111
+ return Buffer.compare(this, otherBuffer) === 0
112
+ }
113
+
103
114
  static copyBytesFrom(view: ArrayBufferView, offset?: number, length?: number): Buffer {
104
115
  if (offset === undefined) offset = 0
105
116
  if (length === undefined) length = view.byteLength - offset
@@ -598,7 +609,21 @@ export class Buffer extends Uint8Array {
598
609
  }
599
610
  }
600
611
 
601
- static poolSize: number = 8192
612
+ inspect(): string {
613
+ let str = ''
614
+ const max = 50 // Default max bytes to inspect
615
+ const len = Math.min(this.length, max)
616
+ for (let i = 0; i < len; i++) {
617
+ if (i > 0) str += ' '
618
+ str += this[i].toString(16).padStart(2, '0')
619
+ }
620
+ if (this.length > max) str += ' ... ' + (this.length - max) + ' more bytes'
621
+ return '<Buffer ' + str + '>'
622
+ }
623
+
624
+ [Symbol.for('nodejs.util.inspect.custom')]() {
625
+ return this.inspect()
626
+ }
602
627
 
603
628
  static isEncoding(encoding: string): boolean {
604
629
  switch (encoding.toLowerCase()) {