Skip to content

Commit

Permalink
fix: Huge file wado-rs
Browse files Browse the repository at this point in the history
fs.readFileSync can not handle 2 GB file.
Use package that can convert stream to buffer to fix thie issuse.

refactor: Move build file to build_raccoon

chore: Ignore build directory

chore: Added package @jorgeferrero/stream-to-buffer

The package can convert stream to buffer
  • Loading branch information
Chinlinlee committed Mar 19, 2021
1 parent 3bf7d4b commit cc65c0d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 174 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ models/dcmtk/dcmtk-3.6.5-win64-dynamic
api/dicom-xml/upload_xml/*.*
mongodb
temp/
build/
7 changes: 4 additions & 3 deletions api/dicom-web/controller/wado-rs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const uuid = require('uuid');
const _ = require('lodash');
const DICOMWebHandleError = require('../../../models/DICOMWeb/httpMessage');
const { writeImageMultipart } = require('../../../models/DICOMWeb')
const { streamToBuffer } = require('@jorgeferrero/stream-to-buffer');
module.exports = async function (req , res) {
let keys = Object.keys(req.params);
console.log(req.headers.accept);
Expand Down Expand Up @@ -218,7 +219,7 @@ let multipartFunc = {
const BOUNDORY = `${uuid.v4()}-${uuid.v4()}`;
for (let i= 0 ; i < imagesPath.length ; i++) {
console.log(`${process.env.DICOM_STORE_ROOTPATH}${imagesPath[i]}`);
let fileBuffer = fs.readFileSync(`${process.env.DICOM_STORE_ROOTPATH}${imagesPath[i]}`);
let fileBuffer = await streamToBuffer(fs.createReadStream(`${process.env.DICOM_STORE_ROOTPATH}${imagesPath[i]}`));
res.write(`${i==0? "":"\n\n"}--${BOUNDORY}\n`);
res.write(`Content-Type: ${type}\n`);
res.write('Content-length: ' + fileBuffer.length + '\n\n');
Expand All @@ -237,7 +238,7 @@ let multipartFunc = {
const BOUNDORY = `${uuid.v4()}-${uuid.v4()}`;
for (let i= 0 ; i < imagesPath.length ; i++) {
console.log(`${process.env.DICOM_STORE_ROOTPATH}${imagesPath[i]}`);
let fileBuffer = fs.readFileSync(`${process.env.DICOM_STORE_ROOTPATH}${imagesPath[i]}`);
let fileBuffer = await streamToBuffer(fs.createReadStream(`${process.env.DICOM_STORE_ROOTPATH}${imagesPath[i]}`));
res.write(`${i==0? "":"\n\n"}--${BOUNDORY}\n`);
res.write(`Content-Type: ${type}\n`);
res.write('Content-length: ' + fileBuffer.length + '\n\n');
Expand All @@ -254,7 +255,7 @@ let multipartFunc = {
let imagesPath = await mongoFunc.getInstanceImagePath(iParam);
if (imagesPath) {
const BOUNDORY = `${uuid.v4()}-${uuid.v4()}`;
let fileBuffer = fs.readFileSync(`${process.env.DICOM_STORE_ROOTPATH}${imagesPath[0]}`);
let fileBuffer = await streamToBuffer(fs.createReadStream(`${process.env.DICOM_STORE_ROOTPATH}${imagesPath[0]}`));
console.log(imagesPath[0]);
res.write(`--${BOUNDORY}\n`);
res.write(`Content-Type: ${type}\n`);
Expand Down
141 changes: 0 additions & 141 deletions build/index.js

This file was deleted.

46 changes: 16 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"license": "MIT",
"dependencies": {
"@asymmetrik/node-fhir-server-core": "^2.0.10",
"@jorgeferrero/stream-to-buffer": "^2.0.6",
"adm-zip": "^0.5.1",
"archiver": "^4.0.1",
"bcrypt": "^5.0.0",
Expand Down

0 comments on commit cc65c0d

Please sign in to comment.