feat: Track binary size of resources when possible

This commit is contained in:
Joachim Van Herwegen
2023-10-02 13:40:19 +02:00
parent 3e9adef4cf
commit 71e55690f3
15 changed files with 194 additions and 35 deletions

View File

@@ -5,7 +5,7 @@ import { ResourceStore } from '../../../src/storage/ResourceStore';
import { InternalServerError } from '../../../src/util/errors/InternalServerError';
import { RangeNotSatisfiedHttpError } from '../../../src/util/errors/RangeNotSatisfiedHttpError';
import { readableToString } from '../../../src/util/StreamUtil';
import { SOLID_HTTP } from '../../../src/util/Vocabularies';
import { POSIX, SOLID_HTTP } from '../../../src/util/Vocabularies';
describe('A BinarySliceResourceStore', (): void => {
const identifier = { path: 'path' };
@@ -31,6 +31,14 @@ describe('A BinarySliceResourceStore', (): void => {
expect(result.metadata.get(SOLID_HTTP.terms.end)?.value).toBe('4');
});
it('uses the stream size when slicing if available.', async(): Promise<void> => {
representation.metadata.set(POSIX.terms.size, '10');
const result = await store.getRepresentation(identifier, { range: { unit: 'bytes', parts: [{ start: -4 }]}});
await expect(readableToString(result.data)).resolves.toBe('6789');
expect(result.metadata.get(SOLID_HTTP.terms.unit)?.value).toBe('bytes');
expect(result.metadata.get(SOLID_HTTP.terms.start)?.value).toBe('-4');
});
it('does not add end metadata if there is none.', async(): Promise<void> => {
const result = await store.getRepresentation(identifier, { range: { unit: 'bytes', parts: [{ start: 5 }]}});
await expect(readableToString(result.data)).resolves.toBe('56789');