mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
Use create*
prefix to clarify curried functions
This commit is contained in:
parent
6e6b93d917
commit
8474f3cf7f
4 changed files with 25 additions and 23 deletions
|
@ -24,10 +24,10 @@ exports.ensureDirectory = async (userDataPath) => {
|
|||
await fse.ensureDir(exports.getPath(userDataPath));
|
||||
};
|
||||
|
||||
// readData :: AttachmentsPath ->
|
||||
// RelativePath ->
|
||||
// IO (Promise ArrayBuffer)
|
||||
exports.readData = (root) => {
|
||||
// createReader :: AttachmentsPath ->
|
||||
// RelativePath ->
|
||||
// IO (Promise ArrayBuffer)
|
||||
exports.createReader = (root) => {
|
||||
if (!isString(root)) {
|
||||
throw new TypeError('`root` must be a path');
|
||||
}
|
||||
|
@ -43,10 +43,10 @@ exports.readData = (root) => {
|
|||
};
|
||||
};
|
||||
|
||||
// writeData :: AttachmentsPath ->
|
||||
// ArrayBuffer ->
|
||||
// IO (Promise RelativePath)
|
||||
exports.writeData = (root) => {
|
||||
// createWriter :: AttachmentsPath ->
|
||||
// ArrayBuffer ->
|
||||
// IO (Promise RelativePath)
|
||||
exports.createWriter = (root) => {
|
||||
if (!isString(root)) {
|
||||
throw new TypeError('`root` must be a path');
|
||||
}
|
||||
|
@ -66,8 +66,10 @@ exports.writeData = (root) => {
|
|||
};
|
||||
};
|
||||
|
||||
// deleteData :: AttachmentsPath -> IO Unit
|
||||
exports.deleteData = (root) => {
|
||||
// createDeleter :: AttachmentsPath ->
|
||||
// RelativePath ->
|
||||
// IO Unit
|
||||
exports.createDeleter = (root) => {
|
||||
if (!isString(root)) {
|
||||
throw new TypeError('`root` must be a path');
|
||||
}
|
||||
|
|
|
@ -127,7 +127,7 @@ const _createMessage = ({ commonProperties, conversationId, type } = {}) => {
|
|||
};
|
||||
|
||||
const FIXTURES_PATH = path.join(__dirname, '..', '..', 'fixtures');
|
||||
const readData = Attachments.readData(FIXTURES_PATH);
|
||||
const readData = Attachments.createReader(FIXTURES_PATH);
|
||||
const createRandomInMemoryAttachment = async () => {
|
||||
const files = (await fs.readdir(FIXTURES_PATH)).map(createFileEntry);
|
||||
const { contentType, fileName } = sample(files);
|
||||
|
|
|
@ -111,9 +111,9 @@ window.ProxyAgent = require('proxy-agent');
|
|||
|
||||
// ES2015+ modules
|
||||
const attachmentsPath = Attachments.getPath(app.getPath('userData'));
|
||||
const deleteAttachmentData = Attachments.deleteData(attachmentsPath);
|
||||
const readAttachmentData = Attachments.readData(attachmentsPath);
|
||||
const writeAttachmentData = Attachments.writeData(attachmentsPath);
|
||||
const deleteAttachmentData = Attachments.createDeleter(attachmentsPath);
|
||||
const readAttachmentData = Attachments.createReader(attachmentsPath);
|
||||
const writeAttachmentData = Attachments.createWriter(attachmentsPath);
|
||||
|
||||
// Injected context functions to keep `Message` agnostic from Electron:
|
||||
const upgradeSchemaContext = {
|
||||
|
|
|
@ -13,7 +13,7 @@ const NAME_LENGTH = 64;
|
|||
const PATH_LENGTH = PREFIX_LENGTH + NUM_SEPARATORS + NAME_LENGTH;
|
||||
|
||||
describe('Attachments', () => {
|
||||
describe('writeData', () => {
|
||||
describe('createWriter', () => {
|
||||
let tempRootDirectory = null;
|
||||
before(() => {
|
||||
tempRootDirectory = tmp.dirSync().name;
|
||||
|
@ -25,9 +25,9 @@ describe('Attachments', () => {
|
|||
|
||||
it('should write file to disk and return path', async () => {
|
||||
const input = stringToArrayBuffer('test string');
|
||||
const tempDirectory = path.join(tempRootDirectory, 'Attachments_writeData');
|
||||
const tempDirectory = path.join(tempRootDirectory, 'Attachments_createWriter');
|
||||
|
||||
const outputPath = await Attachments.writeData(tempDirectory)(input);
|
||||
const outputPath = await Attachments.createWriter(tempDirectory)(input);
|
||||
const output = await fse.readFile(path.join(tempDirectory, outputPath));
|
||||
|
||||
assert.lengthOf(outputPath, PATH_LENGTH);
|
||||
|
@ -37,7 +37,7 @@ describe('Attachments', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('readData', () => {
|
||||
describe('createReader', () => {
|
||||
let tempRootDirectory = null;
|
||||
before(() => {
|
||||
tempRootDirectory = tmp.dirSync().name;
|
||||
|
@ -48,7 +48,7 @@ describe('Attachments', () => {
|
|||
});
|
||||
|
||||
it('should read file from disk', async () => {
|
||||
const tempDirectory = path.join(tempRootDirectory, 'Attachments_readData');
|
||||
const tempDirectory = path.join(tempRootDirectory, 'Attachments_createReader');
|
||||
|
||||
const relativePath = Attachments.getRelativePath(Attachments.createName());
|
||||
const fullPath = path.join(tempDirectory, relativePath);
|
||||
|
@ -57,13 +57,13 @@ describe('Attachments', () => {
|
|||
const inputBuffer = Buffer.from(input);
|
||||
await fse.ensureFile(fullPath);
|
||||
await fse.writeFile(fullPath, inputBuffer);
|
||||
const output = await Attachments.readData(tempDirectory)(relativePath);
|
||||
const output = await Attachments.createReader(tempDirectory)(relativePath);
|
||||
|
||||
assert.deepEqual(input, output);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleteData', () => {
|
||||
describe('createDeleter', () => {
|
||||
let tempRootDirectory = null;
|
||||
before(() => {
|
||||
tempRootDirectory = tmp.dirSync().name;
|
||||
|
@ -74,7 +74,7 @@ describe('Attachments', () => {
|
|||
});
|
||||
|
||||
it('should delete file from disk', async () => {
|
||||
const tempDirectory = path.join(tempRootDirectory, 'Attachments_deleteData');
|
||||
const tempDirectory = path.join(tempRootDirectory, 'Attachments_createDeleter');
|
||||
|
||||
const relativePath = Attachments.getRelativePath(Attachments.createName());
|
||||
const fullPath = path.join(tempDirectory, relativePath);
|
||||
|
@ -83,7 +83,7 @@ describe('Attachments', () => {
|
|||
const inputBuffer = Buffer.from(input);
|
||||
await fse.ensureFile(fullPath);
|
||||
await fse.writeFile(fullPath, inputBuffer);
|
||||
await Attachments.deleteData(tempDirectory)(relativePath);
|
||||
await Attachments.createDeleter(tempDirectory)(relativePath);
|
||||
|
||||
const existsFile = await fse.exists(fullPath);
|
||||
assert.isFalse(existsFile);
|
||||
|
|
Loading…
Reference in a new issue