Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(server/extract): use single transaction for insert/store #491

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/runtime/src/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export namespace Artifact {
return value;
};

export let extract = async (blob: tg.Blob): Promise<Artifact> => {
export let extract = async (blob: tg.Blob | tg.File): Promise<Artifact> => {
if (blob instanceof tg.File) {
blob = await blob.contents();
}
let value = await tg.build({
args: ["extract", blob],
env: undefined,
Expand Down
10 changes: 8 additions & 2 deletions packages/runtime/src/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ export namespace Blob {
};

export let compress = async (
blob: Blob,
blob: Blob | tg.File,
format: CompressionFormat,
): Promise<Blob> => {
if (blob instanceof tg.File) {
blob = await blob.contents();
}
let value = await tg.build({
args: ["compress", blob, format],
env: undefined,
Expand All @@ -82,7 +85,10 @@ export namespace Blob {
return value;
};

export let decompress = async (blob: Blob): Promise<Blob> => {
export let decompress = async (blob: Blob | tg.File): Promise<Blob> => {
if (blob instanceof tg.File) {
blob = await blob.contents();
}
let value = await tg.build({
args: ["decompress", blob],
env: undefined,
Expand Down
12 changes: 6 additions & 6 deletions packages/runtime/tangram.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ declare namespace tg {

/** Compress a blob. **/
export let compress: (
blob: tg.Blob,
blob: tg.Blob | tg.File,
format: tg.Blob.CompressionFormat,
) => Promise<tg.Blob>;

/** Decompress a blob. **/
export let decompress: (
blob: tg.Blob,
blob: tg.Blob | tg.File,
) => Promise<tg.Blob>;

/** Download the contents of a URL. */
Expand All @@ -125,13 +125,13 @@ declare namespace tg {

/** Compress a blob. **/
export let compress: (
blob: tg.Blob,
blob: tg.Blob | tg.File,
format: tg.Blob.CompressionFormat,
) => Promise<tg.Blob>;

/** Decompress a blob. **/
export let decompress: (
blob: tg.Blob,
blob: tg.Blob | tg.File,
) => Promise<tg.Blob>;

/** Download a blob. **/
Expand Down Expand Up @@ -238,7 +238,7 @@ declare namespace tg {

/** Extract an artifact from an archive. **/
export let extract: (
blob: tg.Blob,
blob: tg.Blob | tg.File,
) => Promise<tg.Artifact>;

/** Bundle an artifact. **/
Expand Down Expand Up @@ -271,7 +271,7 @@ declare namespace tg {

/** Extract an artifact from an archive. **/
export let extract: (
blob: tg.Blob,
blob: tg.Blob | tg.File,
) => Promise<tg.Artifact>;

/** Bundle an artifact. **/
Expand Down
6 changes: 3 additions & 3 deletions packages/server/src/blob/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ impl Reader {
.map_err(|source| tg::error!(!source, "failed to execute the statemtent"))?;
let reader = if let Some(row) = row {
let blob_path = server.blobs_path().join(row.blob.to_string());
let file = tokio::fs::File::open(blob_path)
.await
.map_err(|source| tg::error!(!source, "failed to open the file"))?;
let file = tokio::fs::File::open(&blob_path).await.map_err(
|source| tg::error!(!source, %path = blob_path.display(), "failed to open the file"),
)?;
let reader = File::new(file, row.position, row.length).await?;
Self::File(reader)
} else {
Expand Down
Loading