feat(file): Added functionality to retrieve magic bytes from files and detect file types using magic bytes.

This commit is contained in:
2024-11-18 15:07:46 +01:00
parent c7f0c97341
commit 383a5204f4
7 changed files with 6027 additions and 4273 deletions

View File

@@ -50,6 +50,10 @@ export class File {
public parentDirectoryRef: Directory;
public name: string;
/**
* get the full path to the file
* @returns the full path to the file
*/
public getBasePath(): string {
return plugins.path.join(this.parentDirectoryRef.getBasePath(), this.name);
}
@@ -188,7 +192,7 @@ export class File {
if (isDirectory) {
moveToPath = await helpers.reducePathDescriptorToPath({
...pathDescriptorArg,
path: plugins.path.join(pathDescriptorArg.path, this.name),
path: plugins.path.join(pathDescriptorArg.path!, this.name),
});
}
// lets move the file
@@ -230,4 +234,11 @@ export class File {
contents: JSON.stringify(dataArg),
});
}
public async getMagicBytes(optionsArg: { length: number }): Promise<Buffer> {
return this.parentDirectoryRef.bucketRef.getMagicBytes({
path: this.getBasePath(),
length: optionsArg.length
})
}
}