Skip to content

Refactoring es2016nify and HashStream replace createSha1Hash()#35

Closed
segayuu wants to merge 25 commits intohexojs:masterfrom
segayuu:refactoring-from-lebab
Closed

Refactoring es2016nify and HashStream replace createSha1Hash()#35
segayuu wants to merge 25 commits intohexojs:masterfrom
segayuu:refactoring-from-lebab

Conversation

@segayuu
Copy link
Contributor

@segayuu segayuu commented Jul 9, 2018

No description provided.

@coveralls
Copy link

coveralls commented Jul 9, 2018

Coverage Status

Coverage increased (+0.3%) to 97.152% when pulling a0fcd99 on segayuu:refactoring-from-lebab into a1c9e11 on hexojs:master.

@segayuu
Copy link
Contributor Author

segayuu commented Jul 9, 2018

travis ci is causing an error is an error specific to test-cov command.
My development environment is windows, test command did not detect anything other than windows specific errors.

@segayuu
Copy link
Contributor Author

segayuu commented Jul 9, 2018

maybe issue gotwarlost/istanbul#717 ...

@segayuu segayuu requested a review from a team July 9, 2018 05:43
Copy link

@tcrowe tcrowe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests were successful locally

tcrowe
tcrowe previously approved these changes Jul 9, 2018
lib/highlight.js Outdated
});

result += '<figure class="highlight' + (data.language ? ' ' + data.language : '') + '">';
let result = `<figure class="highlight${language ? ` ${language}` : ''}">`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future maybe we can go into some of these ternary expressions and make them more explicit. That was there before so I didn't want to block it for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tcrowe thank review!
As you can see, I set it explicitly.

JLHwung
JLHwung previously approved these changes Jul 9, 2018
Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as the new coverage missing line is of integration with hightlight.js

@segayuu segayuu dismissed stale reviews from JLHwung and tcrowe via 58f0df5 July 10, 2018 00:32
@segayuu
Copy link
Contributor Author

segayuu commented Jul 10, 2018

@JLHwung
https://coveralls.io/builds/16686048/source?filename=lib%2Fhighlight.js
As a result of comparison with the status page of the corresponding file in the master branch, the reason why the coverage rate fell down is probably because the number of lines has been reduced.

@tcrowe
Copy link

tcrowe commented Jul 10, 2018

This will bring ./lib/hash.js coverage to 100%

...
it('HashStream', () => {
  const content1 = '123456';
  const content2 = '654321';
  const stream = new hash.HashStream();

  // explicit convert
  stream.write(Buffer.from(content1));

  // implicit convert
  stream.write(content2);
  stream.end();

  stream.read().should.eql(sha1(content1 + content2));
});
...


CacheStream.prototype._transform = function(chunk, enc, callback) {
var buf = chunk instanceof Buffer ? chunk : Buffer.from(chunk, enc);
const buf = chunk instanceof Buffer ? chunk : Buffer.from(chunk, enc);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't get this Buffer.from branch to run in the test. Can it ever be something other than Buffer? If not the Buffer.from branch can be removed and coverage will be 100%.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can do something tricky like this in ./test/cache_stream.js

it('default', () => {
  const src = new Readable();
  const cacheStream = new CacheStream();
  const content1 = Buffer.from('test1');
  const content2 = 'test2';
  let transformed = false;

  src.push(content1);
  src.push(null);
  src.pipe(cacheStream);

  cacheStream._transform(content2, 'utf8', () => { transformed = true; });

  cacheStream.on('finish', () => {
    cacheStream.getCache().should.eql(content1 + content2);
    transformed.should.be.true;
  });
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://nodejs.org/api/stream.html#stream_transform_transform_chunk_encoding_callback
Even if stream is not an objectMode, it is possible to pass string. For this reason, we need to assume that string will flow.

Copy link
Contributor Author

@segayuu segayuu Jul 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of chank of _transform()...

  • Set decodeStrings of theTransform (super: Writeble)class's constructor option to false.
  • Calling setEncoding() on the source Readable.

Only when it meets the above conditions, it is string, otherwise it is Buffer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After finishing the previous behavior check, in the case of the current implementation, we were able to grasp that chunk is only Buffer ...

@tcrowe
Copy link

tcrowe commented Jul 10, 2018

@segayuu It's looking good. Whenever you feel like it's finished let me know and I'll test, review, & merge.

@segayuu
Copy link
Contributor Author

segayuu commented Jul 11, 2018

@tcrowe thank!
https://nodejs.org/api/crypto.html#crypto_class_hash
https://github.com/nodejs/node/blob/v10.6.0/lib/internal/crypto/hash.js#L42
Hash class is not-objectMode Transform stream class.
The only difference from HashStream is that objectMode is not set.

https://github.com/segayuu/hexo-util/blob/refactoring-from-lebab/lib/hash.js#L19
However, the current implementation of hashStream#_transform() does not assume that object will come.

For this reason, I am worried about whether to implement it so that it can deal with object or worry about deleting implementation other than algorithm as a useless wrapper class.

@tcrowe
Copy link

tcrowe commented Jul 11, 2018

util.HashStream is only used in two places https://github.com/hexojs/hexo/search?q=hashstream&unscoped_q=hashstream

Only String or Buffer go into it.

What do you think we should do?

@segayuu
Copy link
Contributor Author

segayuu commented Jul 11, 2018

For me, the idea is to make the current HashStream a deprecated class and create a new createSha1Hash().
There is also an idea to simply implement as a class that only exposes stream's methods. (Not-objectMode)

@tcrowe
Copy link

tcrowe commented Jul 11, 2018

@segayuu Okay cool! 🤓

- deprecated HashStream()
- HashStream() to no-ObjectMode stream
@segayuu
Copy link
Contributor Author

segayuu commented Jul 11, 2018

@tcrowe It would be greatly appreciated if you could do a second review.

@segayuu segayuu changed the title Refactoring es2016nify Refactoring es2016nify and HashStream replace createSha1Hash() Jul 11, 2018
@tcrowe
Copy link

tcrowe commented Jul 11, 2018

@segayuu Okay! It might be when I wake up in the morning. It's late here now.

@segayuu segayuu requested a review from a team July 30, 2018 02:03
@segayuu
Copy link
Contributor Author

segayuu commented Oct 18, 2018

I waited for January, but I would like to split PR.

@segayuu segayuu closed this Oct 18, 2018
This was referenced Oct 18, 2018
@segayuu segayuu deleted the refactoring-from-lebab branch October 18, 2018 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants