Skip to content

Commit ce2374d

Browse files
committed
File to array buffer directive
1 parent ea3306f commit ce2374d

6 files changed

+42
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fctrlx-file-to-base64",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"peerDependencies": {
55
"@angular/common": "^7.2.0",
66
"@angular/core": "^7.2.0"

src/lib/converted.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ export interface Converted {
33
size: number;
44
type: string;
55
base64?: string;
6+
text?: string;
7+
arrBuf?: any;
68
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {
2+
Directive,
3+
ElementRef,
4+
EventEmitter,
5+
Input,
6+
Output,
7+
} from '@angular/core';
8+
import { Base } from './Base';
9+
10+
@Directive({
11+
selector: '[fileToArrBuf]',
12+
})
13+
export class FctrlxFileToArrayBufferDirective extends Base {
14+
@Input() files: any;
15+
@Input() type: string;
16+
@Input() multiple: undefined | null | string | boolean;
17+
18+
@Output() filesChange: EventEmitter<any> = new EventEmitter();
19+
20+
constructor(element: ElementRef) {
21+
super('fileToArrBuf', element);
22+
}
23+
24+
filesChanged(event: Event): void {
25+
super.filesChanged(event, 'readAsArrayBuffer', 'arrBuf');
26+
}
27+
}

src/lib/fctrlx-file-to-base64.directive.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { Base } from './Base';
1111
selector: '[fileToBase64]',
1212
})
1313
export class FctrlxFileToBase64Directive extends Base {
14-
1514
@Input() files: any;
1615
@Input() type: string;
1716
@Input() multiple: undefined | null | string | boolean;
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { NgModule } from '@angular/core';
22
import { FctrlxFileToBase64Directive } from './fctrlx-file-to-base64.directive';
33
import { FctrlxFileToTextDirective } from './fctrlx-file-to-text.directive';
4+
import { FctrlxFileToArrayBufferDirective } from './fctrlx-file-to-array-buffer.directive';
45

56
@NgModule({
67
imports: [],
7-
declarations: [FctrlxFileToBase64Directive, FctrlxFileToTextDirective],
8-
exports: [FctrlxFileToBase64Directive, FctrlxFileToTextDirective],
8+
declarations: [
9+
FctrlxFileToBase64Directive,
10+
FctrlxFileToTextDirective,
11+
FctrlxFileToArrayBufferDirective,
12+
],
13+
exports: [
14+
FctrlxFileToBase64Directive,
15+
FctrlxFileToTextDirective,
16+
FctrlxFileToArrayBufferDirective,
17+
],
918
})
1019
export class FctrlxFileToBase64 { }

src/lib/fctrlx-file-to-text.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { Base } from './Base';
99

1010
@Directive({
11-
selector: '[fileToText]',
11+
selector: '[fileToText]',
1212
})
1313
export class FctrlxFileToTextDirective extends Base {
1414
@Input() files: any;

0 commit comments

Comments
 (0)