Skip to content

Commit

Permalink
Added the 'deallocate' method to the virtual stored resource management
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Jun 4, 2017
1 parent 7f605b1 commit 7506c3c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 5 deletions.
7 changes: 5 additions & 2 deletions lib/manager/VirtualStoredFSManager.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/// <reference types="node" />
import { IResource, ResourceType, ReturnCallback } from '../resource/IResource';
import { IResource, ResourceType, ReturnCallback, SimpleCallback } from '../resource/IResource';
import { Readable, Writable } from 'stream';
import { SerializedObject } from './ISerializer';
import { FSManager } from './FSManager';
import { Readable, Writable } from 'stream';
export interface IVirtualStoredContentManager {
uid: string;
initialize(callback: (error: Error) => void): any;
read(contentUid: string, callback: ReturnCallback<Readable>): any;
write(contentUid: string, callback: ReturnCallback<Writable>): any;
deallocate(contentId: string, callback: SimpleCallback): any;
allocate(callback: ReturnCallback<string>): any;
allocate(options: any, callback: ReturnCallback<string>): any;
}
Expand All @@ -17,6 +18,7 @@ export declare abstract class VirtualStoredContentManager implements IVirtualSto
abstract read(contentUid: string, callback: ReturnCallback<Readable>): any;
abstract write(contentUid: string, callback: ReturnCallback<Writable>): any;
protected abstract _allocate(options: any, callback: ReturnCallback<string>): any;
abstract deallocate(contentId: string, callback: SimpleCallback): any;
allocate(callback: ReturnCallback<string>): any;
allocate(options: any, callback: ReturnCallback<string>): any;
}
Expand All @@ -34,6 +36,7 @@ export declare class SimpleVirtualStoredContentManager extends VirtualStoredCont
initialize(callback: (error: Error) => void): void;
read(contentUid: string, _callback: ReturnCallback<Readable>): void;
write(contentUid: string, _callback: ReturnCallback<Writable>): void;
deallocate(uid: string, callback: SimpleCallback): void;
protected _allocate(options: any, _callback: ReturnCallback<string>): void;
}
export declare class VirtualStoredFSManager implements FSManager {
Expand Down
3 changes: 3 additions & 0 deletions lib/manager/VirtualStoredFSManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ var SimpleVirtualStoredContentManager = (function (_super) {
}
});
};
SimpleVirtualStoredContentManager.prototype.deallocate = function (uid, callback) {
fs.unlink(path.join(this.storeFolderPath, uid), callback);
};
SimpleVirtualStoredContentManager.prototype._allocate = function (options, _callback) {
var callback = function (_1, _2) { return process.nextTick(function () { return _callback(_1, _2); }); };
if (!this.initialized)
Expand Down
1 change: 1 addition & 0 deletions lib/resource/virtualStored/VirtualStoredFile.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export declare class VirtualStoredFile extends VirtualStoredResource {
len: number;
constructor(name: string, parent?: IResource, fsManager?: FSManager);
create(callback: SimpleCallback): void;
delete(callback: SimpleCallback): void;
type(callback: ReturnCallback<ResourceType>): void;
write(targetSource: boolean, callback: ReturnCallback<Writable>): void;
read(targetSource: boolean, callback: ReturnCallback<Readable>): void;
Expand Down
3 changes: 3 additions & 0 deletions lib/resource/virtualStored/VirtualStoredFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ var VirtualStoredFile = (function (_super) {
callback(e);
});
};
VirtualStoredFile.prototype.delete = function (callback) {
this.fsManager.contentManager.deallocate(this.contentUid, callback);
};
VirtualStoredFile.prototype.type = function (callback) {
callback(null, IResource_1.ResourceType.File);
};
Expand Down
14 changes: 11 additions & 3 deletions src/manager/VirtualStoredFSManager.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IResource, ResourceType, ReturnCallback } from '../resource/IResource'
import { SerializedObject } from './ISerializer'
import { IResource, ResourceType, ReturnCallback, SimpleCallback } from '../resource/IResource'
import { VirtualStoredFolder } from '../resource/virtualStored/VirtualStoredFolder'
import { Readable, Writable } from 'stream'
import { VirtualStoredFile } from '../resource/virtualStored/VirtualStoredFile'
import { SerializedObject } from './ISerializer'
import { FSManager } from './FSManager'
import { Errors } from '../Errors'
import { Readable, Writable } from 'stream'
import * as path from 'path'
import * as fs from 'fs'

Expand All @@ -17,6 +17,8 @@ export interface IVirtualStoredContentManager
read(contentUid : string, callback : ReturnCallback<Readable>)
write(contentUid : string, callback : ReturnCallback<Writable>)

deallocate(contentId : string, callback : SimpleCallback);

allocate(callback : ReturnCallback<string>);
allocate(options : any, callback : ReturnCallback<string>)
}
Expand All @@ -28,6 +30,7 @@ export abstract class VirtualStoredContentManager implements IVirtualStoredConte
abstract read(contentUid : string, callback : ReturnCallback<Readable>)
abstract write(contentUid : string, callback : ReturnCallback<Writable>)
protected abstract _allocate(options : any, callback : ReturnCallback<string>)
abstract deallocate(contentId : string, callback : SimpleCallback);

allocate(callback : ReturnCallback<string>);
allocate(options : any, callback : ReturnCallback<string>)
Expand Down Expand Up @@ -128,6 +131,11 @@ export class SimpleVirtualStoredContentManager extends VirtualStoredContentManag
}
})
}

deallocate(uid : string, callback : SimpleCallback)
{
fs.unlink(path.join(this.storeFolderPath, uid), callback);
}

protected _allocate(options : any, _callback : ReturnCallback<string>)
{
Expand Down
4 changes: 4 additions & 0 deletions src/resource/virtualStored/VirtualStoredFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class VirtualStoredFile extends VirtualStoredResource
callback(e);
})
}
delete(callback : SimpleCallback)
{
(this.fsManager as VirtualStoredFSManager).contentManager.deallocate(this.contentUid, callback);
}

// ****************************** Std meta-data ****************************** //
type(callback : ReturnCallback<ResourceType>)
Expand Down
Empty file.

0 comments on commit 7506c3c

Please sign in to comment.