Can we add some additional information in a file?

65 views Asked by At

I want a file to carry some additional information like a Id of a record.

Can we add some additional metadata or anything in a file?

Can we add some additional byte stream which do not corrupt the file?

Please help me.

Thanks

1

There are 1 answers

1
Alex Kolarski On

Yes, you can write metadata to files using what is called extended attributes. Here is a wiki link for more information on that (https://en.wikipedia.org/wiki/Extended_file_attributes)

It depends on what language are you going to read and write to this attributes.

For example in PHP you can use the PECL library xattr's function (http://php.net/manual/en/function.xattr-set.php)

On Node.JS you would use a library like that fs-xattr (https://www.npmjs.com/package/fs-xattr)

Notes:

  1. Keep in mind that different file systems have different specs.
  2. You have limited size depending on the filesystem
  3. There are specifications for particular file extensions and different ways to write to them depending on your programming language.

For example there is Exif (https://en.wikipedia.org/wiki/Exchangeable_image_file_format#Example) for JPEG images.

Or ID3 (https://en.wikipedia.org/wiki/ID3) for MP3 and etc.