Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(options: { source: ExternalSource, outputSize?: number }) {
// $FlowIKnow Use of Object.prototype
if (!options || typeof options !== 'object' || Object.getPrototypeOf(options) !== Object.prototype)
throw new InvalidArgument('options', 'object', options);
const { source, outputSize } = options;
assertDataType(source, 'options.source');
if (outputSize && typeof outputSize !== 'number')
throw new InvalidArgument('options.outputSize', 'number', outputSize);
super({
// buffering a single output chunk
objectMode: true,
highWaterMark: 1,
});
this._outputSize = outputSize || 5 * 1024 * 1024; // 5MB
if (source instanceof ArrayBuffer || source instanceof Uint8Array) { // also catches Buffer
this._initBinaryMode(source);
} else {
this._initFileMode(source);
async upload(clearData: Data, options?: $Shape & ProgressOptions> = {}): Promise {
this.assert(statuses.READY, 'upload a file');
assertDataType(clearData, 'clearData');
const outputOptions = extractOutputOptions(options, clearData);
const progressOptions = extractProgressOptions(options);
const sharingOptions = extractSharingOptions(options);
return this._session.upload(clearData, sharingOptions, outputOptions, progressOptions);
}
async encryptData(clearData: Data, options?: $Shape & ProgressOptions> = {}): Promise {
this.assert(statuses.READY, 'encrypt data');
assertDataType(clearData, 'clearData');
const outputOptions = extractOutputOptions(options, clearData);
const progressOptions = extractProgressOptions(options);
const sharingOptions = extractSharingOptions(options);
return this._session.encryptData(clearData, sharingOptions, outputOptions, progressOptions);
}
async decryptData(encryptedData: Data, options?: $Shape & ProgressOptions> = {}): Promise {
this.assert(statuses.READY, 'decrypt data');
assertDataType(encryptedData, 'encryptedData');
const outputOptions = extractOutputOptions(options, encryptedData);
const progressOptions = extractProgressOptions(options);
return this._session.decryptData(encryptedData, outputOptions, progressOptions);
}
async getResourceId(encryptedData: Uint8Array): Promise {
this.assert(statuses.READY, 'get a resource id');
assertDataType(encryptedData, 'encryptedData');
const castEncryptedData = await castData(encryptedData, { type: Uint8Array }, SAFE_EXTRACTION_LENGTH);
const encryption = extractEncryptionFormat(castEncryptedData);
return utils.toBase64(encryption.extractResourceId(castEncryptedData));
}