This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ping): convert the ping messages to lowercase
- Loading branch information
Showing
6 changed files
with
94 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict' | ||
|
||
// Converts IPFS API ping messages to lowercase | ||
// | ||
// { | ||
// Success: true, | ||
// Text: 'foobar', | ||
// Time: 0 | ||
// } | ||
// | ||
|
||
module.exports = function pingMessageConverter (obj) { | ||
if (!isPingMessage(obj)) throw new Error('Invalid ping message received') | ||
return { | ||
success: obj.Success, | ||
time: obj.Time, | ||
text: obj.Text | ||
} | ||
} | ||
|
||
function isPingMessage (obj) { | ||
return obj && typeof obj.Success === 'boolean' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict' | ||
|
||
const TransformStream = require('readable-stream').Transform | ||
const pingMessageConverter = require('./ping-message-converter') | ||
|
||
class PingMessageStream extends TransformStream { | ||
constructor (options) { | ||
const opts = Object.assign(options || {}, { objectMode: true }) | ||
super(opts) | ||
} | ||
|
||
_transform (obj, enc, callback) { | ||
try { | ||
const msg = pingMessageConverter(obj) | ||
this.push(msg) | ||
} catch (err) { | ||
return callback(err) | ||
} | ||
callback() | ||
} | ||
} | ||
|
||
module.exports = PingMessageStream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters