jamhall/s3rver

Calling HEAD on an empty file will return an error

Closed this issue · 3 comments

ksnll commented

When trying to put an empty file, content here will be null and will fail with Cannot read property 'destroy' of null
Current s3 behaviour is to handle the empty file correctly

I'm not able to reproduce making object.content null when putting an empty file. Within S3rver I'm seeing an empty stream, and when retrieving the object via the Node.js aws-sdk it correctly gives an empty Buffer. The following test I attempted works just fine:

  it("should store an empty object in a bucket", async function() {
    await s3Client
      .putObject({
        Bucket: buckets[0].name,
        Key: "somekey",
        Body: fs.createReadStream('./empty')
      })
      .promise();
    const object = await s3Client
      .getObject({ Bucket: buckets[0].name, Key: "somekey" })
      .promise();
    expect(object.ETag).to.match(/"[a-fA-F0-9]{32}"/);
  });

where "empty" is a zero-byte file.

ksnll commented

Thanks for having a look 👍
I think it's getting triggered only by the HEAD method after the object has been PUT
If you need more context let me know

I was able reproduce this by modifying that test to use HEAD instead, so thank you for the suggestion. It was a subtle bug but fortunately had a simple fix. I think I should finally have some time to put together a release tonight, thanks for your patience.