bare-rpc 0.1.1 → 0.1.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.
@@ -13,11 +13,11 @@ module.exports = class RPCIncomingRequest {
13
13
  this._responseStream = null
14
14
  }
15
15
 
16
- reply (data) {
16
+ reply (data, encoding) {
17
17
  if (this.sent) throw errors.ALREADY_SENT('Response has already been sent')
18
18
  this.sent = true
19
19
 
20
- this.rpc._sendResponse(this, typeof data === 'string' ? b4a.from(data) : data)
20
+ this.rpc._sendResponse(this, typeof data === 'string' ? b4a.from(data, encoding) : data)
21
21
  }
22
22
 
23
23
  createResponseStream (opts = {}) {
@@ -17,15 +17,17 @@ module.exports = class RPCOutgoingRequest {
17
17
  this._responseStream = null
18
18
  }
19
19
 
20
- send (data) {
20
+ send (data, encoding) {
21
21
  if (this.sent) throw errors.ALREADY_SENT('Request has already been sent')
22
22
  this.sent = true
23
23
 
24
- this.rpc._sendRequest(this, typeof data === 'string' ? b4a.from(data) : data)
24
+ this.rpc._sendRequest(this, typeof data === 'string' ? b4a.from(data, encoding) : data)
25
25
  }
26
26
 
27
- reply () {
28
- return this._promise
27
+ reply (encoding) {
28
+ return encoding && encoding !== 'buffer'
29
+ ? this._promise.then((data) => b4a.toString(data, encoding))
30
+ : this._promise
29
31
  }
30
32
 
31
33
  createRequestStream (opts = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-rpc",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "librpc ABI compatible RPC for Bare",
5
5
  "exports": {
6
6
  ".": "./index.js",