diff --git a/app/ServerUnit.js b/app/ServerUnit.js index 93da8a1..ee91f41 100644 --- a/app/ServerUnit.js +++ b/app/ServerUnit.js @@ -9,6 +9,7 @@ const StreamTake = require('./ws/StreamTake') const Socket = require('./ws/Socket') const { Unit } = require('libflitter') const { NodeDescriptorType } = require('./enum') +const CombinedStream = require('combined-stream') const { Buffer } = require('buffer') const { Readable } = require('stream') @@ -86,10 +87,12 @@ class ServerUnit extends Unit { } } - console.log('write stream', stream) - console.log('write data', { placeholder, position, length }) + const encoded_buffer = await this._bufferStream(stream) + const decoded_buffer = new Buffer(encoded_buffer.toString(), 'base64') - stream.pipe(fs.createWriteStream(placeholder.path, { flags: 'r+', start: position })) + const combined_stream = CombinedStream.create() + combined_stream.append(decoded_buffer) + combined_stream.pipe(fs.createWriteStream(placeholder.path, { flags: 'r+', start: position })) } _bufferStream(stream) { diff --git a/package.json b/package.json index ba47078..8769ba2 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "author": "Garrett Mills (https://garrettmills.dev/)", "license": "MIT", "dependencies": { + "combined-stream": "^1.0.8", "express-ws": "^4.0.0", "flitter-auth": "^0.19.1", "flitter-cli": "^0.16.0", diff --git a/yarn.lock b/yarn.lock index 7f764de..9e43f12 100644 --- a/yarn.lock +++ b/yarn.lock @@ -988,6 +988,13 @@ colors@^1.1.0, colors@^1.3.3: resolved "https://registry.yarnpkg.com/colors/-/colors-1.3.3.tgz#39e005d546afe01e01f9c4ca8fa50f686a01205d" integrity sha512-mmGt/1pZqYRjMxB1axhTo16/snVZ5krrKkcmMeVKxzECMMXoCgnvTPp10QgHfcbQZw8Dq2jMNG6je4JlWU0gWg== +combined-stream@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" + integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== + dependencies: + delayed-stream "~1.0.0" + command-line-args@^5.0.2: version "5.1.1" resolved "https://registry.yarnpkg.com/command-line-args/-/command-line-args-5.1.1.tgz#88e793e5bb3ceb30754a86863f0401ac92fd369a" @@ -1228,6 +1235,11 @@ del@^4.1.0: pify "^4.0.1" rimraf "^2.6.3" +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + integrity sha1-3zrhmayt+31ECqrgsp4icrJOxhk= + delegates@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a"