-
Notifications
You must be signed in to change notification settings - Fork 2
Add(concat): prefix and suffix options (fix #48) #57
base: master
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,3 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .vscode
folder should not be pushed to git. Remove this & add it to the .gitignore in the root directory.
* | ||
* suffix and prefix features | ||
* @param suffix || null @param prefix || null | ||
* appending additional suffix and prefix to each data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This JSDoc comment is incorrect:
- Each param definition should be on its own line
- Description should only be before the param comments start
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if i add the comment like:
/**
* options assign
* @param suffix adding string at the end of the each file
* @param prefix adding string at the beginning of the first packet
*/
var opts = Object.assign({}, ctx.args[0] || {})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The opts i will fix it
var opts = Object.assign({}, ctx.args[0] || {}) | ||
|
||
// suffix | ||
if (opts.suffix) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefix should only be added if this data packet is the first packet (which it will not always be).
Check if it is the first data piece before adding a prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do i know how many packets are coming, can i modified the ctx which will store a count?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no way to know how many packets but you don't need a count. You just need to know what the first one is & what the last one is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel stupid, which props i can check is the first or the last?
/** | ||
* options assign | ||
*/ | ||
var opts = Object.assign({}, ctx.args[0] || {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only necessary if you are going to modify the opts object, which you aren't. Since you are not modifying the opts, you can just do this: const opts = ctx.args[0]
Also avoid using var
in ES2015 code. Use let
or const
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If i changed to javascript const opts=ctx.args[0]
would be an error of suffix undefined. so i changed javascript const opts =ctx.args[0] || {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(y)
// suffix | ||
if (opts.suffix) { | ||
data.size += opts.suffix.length | ||
data.body = Buffer.from(opts.suffix + data.body.toString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Providing a Buffer is unnecessary. You can just provide a string like this:
data.body = opts.suffix + data.body.toString()
data.body = Buffer.from(opts.suffix + data.body.toString()) | ||
} | ||
|
||
// prefix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefix should be before data and suffix should be after.
} | ||
|
||
// prefix | ||
if (opts.prefix) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suffix should only be added if data.end
is true (i.e. it is the last piece of data)
Codecov Report
@@ Coverage Diff @@
## master #57 +/- ##
=========================================
- Coverage 7.57% 7.53% -0.04%
=========================================
Files 61 61
Lines 2692 2706 +14
=========================================
Hits 204 204
- Misses 2488 2502 +14
Continue to review full report at Codecov.
|
So what am i fixing next? @karimsa |
Relevant issues & PRs
See #48.
Checklist