-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FABN-1342] Improve SDK packaging performance (#47)
Use custom writable stream implementation instead of inefficient stream-buffers package when building smart contract packages. Signed-off-by: Simon Stone <[email protected]> Change-Id: I51de2aa6cc62933340dd31e6b3af36f376c6f646
- Loading branch information
1 parent
cf63bcc
commit 9e9ec9e
Showing
10 changed files
with
92 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2019 IBM All Rights Reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const stream = require('stream'); | ||
|
||
class BufferStream extends stream.PassThrough { | ||
|
||
constructor() { | ||
super(); | ||
this.buffers = []; | ||
this.on('data', (chunk) => { | ||
this.buffers.push(chunk); | ||
}); | ||
} | ||
|
||
toBuffer() { | ||
return Buffer.concat(this.buffers); | ||
} | ||
|
||
} | ||
|
||
module.exports = BufferStream; |
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
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,43 @@ | ||
/* | ||
* Copyright 2019 IBM All Rights Reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const BufferStream = require('../../lib/packager/BufferStream'); | ||
require('chai').should(); | ||
|
||
describe('BufferStream', () => { | ||
|
||
describe('#toBuffer', () => { | ||
|
||
it('should return an empty buffer when no buffers written', () => { | ||
const bufferStream = new BufferStream(); | ||
bufferStream.toBuffer().should.have.lengthOf(0); | ||
}); | ||
|
||
it('should return the correct buffer when one buffer is written', () => { | ||
const bufferStream = new BufferStream(); | ||
bufferStream.write(Buffer.from('hello world')); | ||
const buffer = bufferStream.toBuffer(); | ||
buffer.should.have.lengthOf(11); | ||
buffer.toString().should.equal('hello world'); | ||
}); | ||
|
||
it('should return the correct buffer when multiple buffers are written', () => { | ||
const bufferStream = new BufferStream(); | ||
bufferStream.write(Buffer.from('hello')); | ||
bufferStream.write(Buffer.from(' ')); | ||
bufferStream.write(Buffer.from('world')); | ||
bufferStream.write(Buffer.from(' from ')); | ||
bufferStream.write(Buffer.from('multiple buffers')); | ||
const buffer = bufferStream.toBuffer(); | ||
buffer.should.have.lengthOf(33); | ||
buffer.toString().should.equal('hello world from multiple buffers'); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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