I need to unzip a tar file in a serverless API route, is it possible?
Unanswered
Cinnamon posted this in #help-forum
CinnamonOP
I'm trying to download a zip file, untar it, pull out two files and send them to another service.
This route fails to deploy when I call tar.extract() so I'm guessing vercel blocks this (doesn't throw a helpful error message, just fails silently).
My guess is that I'll need to stream this zip file into memory instead of disk (but these files are 200-300MB so that could get fun)
Am I right that Vercel doesn't allow this level of file i/o? Is that documented anywhere? Or is it maybe just an issue with this 3rd party tar package?
Curious if others are able to do this and what the best practices are around it.
This route fails to deploy when I call tar.extract() so I'm guessing vercel blocks this (doesn't throw a helpful error message, just fails silently).
My guess is that I'll need to stream this zip file into memory instead of disk (but these files are 200-300MB so that could get fun)
Am I right that Vercel doesn't allow this level of file i/o? Is that documented anywhere? Or is it maybe just an issue with this 3rd party tar package?
Curious if others are able to do this and what the best practices are around it.
const pipeline = promisify(stream.pipeline);
const uniqueId = uuidv4();
const isDev = process.env.NODE_ENV === 'development';
console.log('Is dev: ', isDev)
const tempDir = isDev? join(tmpdir(), uniqueId) : '/tmp' ;
if(isDev) {
await mkdirSync(tempDir, { recursive: true });
}
const tempFilePath = join(tempDir, `trained_model.tar`);
const response = await axios({
method: 'get',
url: url,
responseType: 'stream',
});
console.log('Fetched tar file, starting stream');
await pipeline(response.data, createWriteStream(tempFilePath));
await tar.extract({ cwd: tempDir, file: tempFilePath });24 Replies
CinnamonOP
bump
I would reach out at #vercel-help I know its not a nextjs limitation, you could validate this is a vercel issue by attempting to do everything locally first.
Sun bear
This is a bad idea
@Sun bear This is a bad idea
CinnamonOP
tell me more
Sun bear
hosting a 200mb file on vercel is just asking to get a one million dollar hosting bill...
CinnamonOP
im not trying to host it
😂 I think just talking about injesting it in memory
ingesting* it
CinnamonOP
I'm trying to fetch it, unzip it, send it somewhere else
basic i/o inside a serverless function
Where you trying to send it that you dont want it zipped"
CinnamonOP
for more details, I'm training a finetune SDXL model in Service A but then doing inference on Service B. Service A zips two sets of model weights into one tarball, Service B needs those files uploaded separately.
so its :
const weightsTarball = serviceA.fetchWeights(url)
const files = unzip(weightsTarball)
for (file in files) serviceB.uploadAsset(file)
const weightsTarball = serviceA.fetchWeights(url)
const files = unzip(weightsTarball)
for (file in files) serviceB.uploadAsset(file)
Ye Its a fair reason, still a vercel issue, so I would go over there.
I self host, so never ran into anything like this
CinnamonOP
i dont have perm to post in #vercel-help but I'll file a support ticket
im curious about streaming the zip file into memory instead of writing to a file
but my file io chops arent super strong.
not sure if thats feasible given the constraints of a serverless api route
Yeah im not even 100% sure what you have access to from the vercel side as far as IO and stuff.
CinnamonOP
This issue is the only place that mentions using
https://github.com/vercel/vercel/discussions/5320
/tmp but it links out to docs that DNE so im guessing vercel isnt trying to support this kind of thinghttps://github.com/vercel/vercel/discussions/5320
Looks like S3FS might be an option but really didnt want to have to setup another service for 1 line of code...
CinnamonOP
Hmmm, it might be caused by the
This is the error thats thrown
but its failing on deployment.
others are seeing this error message for certain 3rd party libs: https://github.com/orgs/vercel/discussions/6575
tar library itself and not be a file io issue. This is the error thats thrown
Error: ENOENT: no such file or directory, lstat '/vercel/path0/.next/export-detail.json' << no real helpful info in therebut its failing on deployment.
others are seeing this error message for certain 3rd party libs: https://github.com/orgs/vercel/discussions/6575