mirror of
https://github.com/diced/zipline.git
synced 2025-04-11 23:31:17 -05:00
fix: revert range getting for datasource
This commit is contained in:
parent
6b1c65bb08
commit
d81eb64061
5 changed files with 10 additions and 26 deletions
|
@ -7,6 +7,6 @@ export abstract class Datasource {
|
|||
public abstract delete(file: string): Promise<void>;
|
||||
public abstract clear(): Promise<void>;
|
||||
public abstract size(file: string): Promise<number | null>;
|
||||
public abstract get(file: string, start?: number, end?: number): Readable | Promise<Readable>;
|
||||
public abstract get(file: string): Readable | Promise<Readable>;
|
||||
public abstract fullSize(): Promise<number>;
|
||||
}
|
||||
|
|
|
@ -26,12 +26,12 @@ export class Local extends Datasource {
|
|||
}
|
||||
}
|
||||
|
||||
public get(file: string, start: number = 0, end: number = Infinity): ReadStream {
|
||||
public get(file: string): ReadStream {
|
||||
const full = join(this.path, file);
|
||||
if (!existsSync(full)) return null;
|
||||
|
||||
try {
|
||||
return createReadStream(full, { start, end });
|
||||
return createReadStream(full);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -45,28 +45,12 @@ export class S3 extends Datasource {
|
|||
});
|
||||
}
|
||||
|
||||
public get(file: string, start: number = 0, end: number = Infinity): Promise<Readable> {
|
||||
if (start === 0 && end === Infinity) {
|
||||
return new Promise((res) => {
|
||||
this.s3.getObject(this.config.bucket, file, (err, stream) => {
|
||||
if (err) res(null);
|
||||
else res(stream);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public get(file: string): Promise<Readable> {
|
||||
return new Promise((res) => {
|
||||
this.s3.getPartialObject(
|
||||
this.config.bucket,
|
||||
file,
|
||||
start,
|
||||
// undefined means to read the rest of the file from the start (offset)
|
||||
end === Infinity ? undefined : end,
|
||||
(err, stream) => {
|
||||
if (err) res(null);
|
||||
else res(stream);
|
||||
},
|
||||
);
|
||||
this.s3.getObject(this.config.bucket, file, (err, stream) => {
|
||||
if (err) res(null);
|
||||
else res(stream);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ function dbFileDecorator(fastify: FastifyInstance, _, done) {
|
|||
.send();
|
||||
if (rangeEnd === Infinity) rangeEnd = size - 1;
|
||||
|
||||
const data = await this.server.datasource.get(file.name, rangeStart, rangeEnd);
|
||||
const data = await this.server.datasource.get(file.name);
|
||||
|
||||
// only send content-range if the client asked for it
|
||||
if (this.request.headers.range) {
|
||||
|
|
|
@ -26,7 +26,7 @@ function rawFileDecorator(fastify: FastifyInstance, _, done) {
|
|||
.send();
|
||||
if (rangeEnd === Infinity) rangeEnd = size - 1;
|
||||
|
||||
const data = await this.server.datasource.get(id, rangeStart, rangeEnd + 1);
|
||||
const data = await this.server.datasource.get(id);
|
||||
|
||||
// only send content-range if the client asked for it
|
||||
if (this.request.headers.range) {
|
||||
|
|
Loading…
Add table
Reference in a new issue