aboutsummaryrefslogtreecommitdiff
path: root/src/files.ts
diff options
context:
space:
mode:
authorjw2552018-04-23 13:54:17 +0100
committerjw2552018-04-23 13:54:17 +0100
commitfac0433557ac9556d48a9bb2421ac96ff220786d (patch)
tree20ec191c4945f926d0bb21a5f29e792308bf543f /src/files.ts
parentremoved R_eport (diff)
downloadmedicine-fac0433557ac9556d48a9bb2421ac96ff220786d.tar.gz
medicine-fac0433557ac9556d48a9bb2421ac96ff220786d.zip

fixed various tests and errors

Diffstat (limited to 'src/files.ts')
-rw-r--r--src/files.ts16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/files.ts b/src/files.ts
index 19862d1..f5d5986 100644
--- a/src/files.ts
+++ b/src/files.ts
@@ -15,8 +15,7 @@ import { toCSV as excelToCSV, buildSupportedViews } from './conversion/csv/excel
const readDir = require('util').promisify(fs.readdir);
const readFile = require('util').promisify(fs.readFile);
-
-const BASE_BASE: string = '/cs/scratch/cjd24/'
+const BASE_BASE: string = `/cs/scratch/${require("os").userInfo().username}/`
const CONTENT_BASE_DIRECTORY: string = BASE_BASE + 'files';
const LOG_BASE_DIRECTORY: string = BASE_BASE + 'logs';
const TEMP_BASE_DIRECTORY: string = BASE_BASE + 'files-temp';
@@ -123,18 +122,17 @@ export const tempPath: (file: string, project: string) => string = (
export const saveFile: (data: Buffer, projectName: string, fileId: string, query: Query) => Promise<void> =
async(data: Buffer, projectName: string, fileId: string, query: Query): Promise<void> => {
- // TODO only overwrite beginning of file and keep rest of data
// Ensure file exists
await fs.ensureFile(path(fileId, projectName));
// Truncate to offset
await truncateFile(fileId, projectName, query.offset || 0);
// Open streams to append to file
- const rStream: stream.PassThrough = new stream.PassThrough();
- rStream.end(data);
- const wStream: fs.WriteStream =
- fs.createWriteStream(path(fileId, projectName), { flags: 'a' });
- rStream.pipe(wStream).on('error', (err: Error) => {
- throw new RequestError(500, `Error while saving file to proper location: ${err}`);
+ fs.writeFile(path(fileId, projectName), data, "binary", (err: any) => {
+ if (err) {
+ logger.failure(err);
+ } else {
+ logger.debug('The file was saved successfully');
+ }
});
};