Skip to content

Commit 2d58c9a

Browse files
mohitpubnubMohit Tejanipubnub-release-bot
authored
React native/files types (#490)
* added ReadableFile types filedata for react native target to use durin files operations * fix minor lint * PubNub SDK v10.2.7 release. --------- Co-authored-by: Mohit Tejani <mohit.tejani@Mohits-MacBook-Pro.local> Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com>
1 parent 32cc0bd commit 2d58c9a

12 files changed

Lines changed: 180 additions & 16 deletions

File tree

.pubnub.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
---
22
changelog:
3+
- date: 2026-02-11
4+
version: v10.2.7
5+
changes:
6+
- type: improvement
7+
text: "PubNubFile to support `ReadableFile` type for React Native target platform."
38
- date: 2026-01-13
49
version: v10.2.6
510
changes:
@@ -1384,7 +1389,7 @@ supported-platforms:
13841389
- 'Ubuntu 14.04 and up'
13851390
- 'Windows 7 and up'
13861391
version: 'Pubnub Javascript for Node'
1387-
version: '10.2.6'
1392+
version: '10.2.7'
13881393
sdks:
13891394
- full-name: PubNub Javascript SDK
13901395
short-name: Javascript
@@ -1400,7 +1405,7 @@ sdks:
14001405
- distribution-type: source
14011406
distribution-repository: GitHub release
14021407
package-name: pubnub.js
1403-
location: https://github.com/pubnub/javascript/archive/refs/tags/v10.2.6.zip
1408+
location: https://github.com/pubnub/javascript/archive/refs/tags/v10.2.7.zip
14041409
requires:
14051410
- name: 'agentkeepalive'
14061411
min-version: '3.5.2'
@@ -2071,7 +2076,7 @@ sdks:
20712076
- distribution-type: library
20722077
distribution-repository: GitHub release
20732078
package-name: pubnub.js
2074-
location: https://github.com/pubnub/javascript/releases/download/v10.2.6/pubnub.10.2.6.js
2079+
location: https://github.com/pubnub/javascript/releases/download/v10.2.7/pubnub.10.2.7.js
20752080
requires:
20762081
- name: 'agentkeepalive'
20772082
min-version: '3.5.2'

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v10.2.7
2+
February 11 2026
3+
4+
#### Modified
5+
- PubNubFile to support `ReadableFile` type for React Native target platform.
6+
17
## v10.2.6
28
January 13 2026
39

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2
2727
npm install pubnub
2828
```
2929
* or download one of our builds from our CDN:
30-
* https://cdn.pubnub.com/sdk/javascript/pubnub.10.2.6.js
31-
* https://cdn.pubnub.com/sdk/javascript/pubnub.10.2.6.min.js
30+
* https://cdn.pubnub.com/sdk/javascript/pubnub.10.2.7.js
31+
* https://cdn.pubnub.com/sdk/javascript/pubnub.10.2.7.min.js
3232
3333
2. Configure your keys:
3434

dist/web/pubnub.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5438,7 +5438,7 @@
54385438
return base.PubNubFile;
54395439
},
54405440
get version() {
5441-
return '10.2.6';
5441+
return '10.2.7';
54425442
},
54435443
getVersion() {
54445444
return this.version;

dist/web/pubnub.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/core/components/configuration.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ const makeConfiguration = (base, setupCryptoModule) => {
168168
return base.PubNubFile;
169169
},
170170
get version() {
171-
return '10.2.6';
171+
return '10.2.7';
172172
},
173173
getVersion() {
174174
return this.version;

lib/file/modules/react-native.js

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,52 @@ class PubNubFile {
3535
const contents = file.data;
3636
fileMimeType = file.mimeType;
3737
fileName = file.name;
38-
fileData = new File([contents], fileName, { type: fileMimeType });
39-
contentLength = fileData.size;
38+
// create a ReadableFile wrapper for ArrayBuffer data
39+
if (contents instanceof ArrayBuffer || ArrayBuffer.isView(contents)) {
40+
// Create ReadableFile wrapper for ArrayBuffer
41+
const arrayBuffer = contents instanceof ArrayBuffer ? contents : contents.buffer;
42+
contentLength = arrayBuffer.byteLength;
43+
fileData = {
44+
arrayBuffer: () => __awaiter(this, void 0, void 0, function* () { return arrayBuffer; }),
45+
blob: () => __awaiter(this, void 0, void 0, function* () {
46+
throw new Error('toBlob() is not supported in React Native environment. Use toArrayBuffer() instead.');
47+
}),
48+
text: () => __awaiter(this, void 0, void 0, function* () {
49+
const decoder = new TextDecoder();
50+
return decoder.decode(arrayBuffer);
51+
}),
52+
};
53+
}
54+
else if (typeof contents === 'string') {
55+
// Handle string data
56+
const encoder = new TextEncoder();
57+
const arrayBuffer = encoder.encode(contents).buffer;
58+
contentLength = arrayBuffer.byteLength;
59+
fileData = {
60+
arrayBuffer: () => __awaiter(this, void 0, void 0, function* () { return arrayBuffer; }),
61+
blob: () => __awaiter(this, void 0, void 0, function* () { return new Blob([contents], { type: fileMimeType }); }),
62+
text: () => __awaiter(this, void 0, void 0, function* () { return contents; }),
63+
};
64+
}
65+
else if (contents instanceof Blob) {
66+
// Handle Blob data
67+
contentLength = contents.size;
68+
fileData = {
69+
arrayBuffer: () => __awaiter(this, void 0, void 0, function* () { return yield contents.arrayBuffer(); }),
70+
blob: () => __awaiter(this, void 0, void 0, function* () { return contents; }),
71+
text: () => __awaiter(this, void 0, void 0, function* () { return yield contents.text(); }),
72+
};
73+
}
74+
else {
75+
// Fallback: Try to use File constructor (may still fail in some environments)
76+
try {
77+
fileData = new File([contents], fileName, { type: fileMimeType });
78+
contentLength = fileData.size;
79+
}
80+
catch (error) {
81+
throw new Error(`Unable to create file from provided data type. ArrayBuffer, Blob, or string expected.Error: ${error}`);
82+
}
83+
}
4084
}
4185
else if ('uri' in file) {
4286
fileMimeType = file.mimeType;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pubnub",
3-
"version": "10.2.6",
3+
"version": "10.2.7",
44
"author": "PubNub <support@pubnub.com>",
55
"description": "Publish & Subscribe Real-time Messaging with PubNub",
66
"scripts": {

src/core/components/configuration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export const makeConfiguration = (
236236
return base.PubNubFile;
237237
},
238238
get version(): string {
239-
return '10.2.6';
239+
return '10.2.7';
240240
},
241241
getVersion(): string {
242242
return this.version;

0 commit comments

Comments
 (0)