reboottime / WebDevelopment

Some notes, thoughts and articles aggregated here about UI/UX and web development.
6 stars 0 forks source link

File manipulation on client(browser) side #91

Open reboottime opened 1 year ago

reboottime commented 1 year ago

PDF manipulation on Frontend Side

reboottime commented 1 year ago

References

  1. FileReader
  2. Blob
  3. File
  4. ASCII

    ASCII (American Standard Code for Information Interchange) is a character encoding standard that was first developed in the 1960s. It is a character encoding that assigns a unique number to each character in the English alphabet, as well as numbers, punctuation marks, and other common symbols. In the ASCII encoding scheme, each character is represented by a 7-bit binary number, which means that there are a total of 128 different characters that can be represented. The ASCII standard includes characters such as uppercase and lowercase letters, digits, punctuation marks, and control characters like line feed and carriage return.

The ASCII encoding scheme is widely used in computer systems and is supported by almost all modern operating systems and programming languages. It is used to represent text in a variety of applications, such as email messages, text files, and source code. Example of ASCII:

 `H   e   l   l   o   ,       w   o   r   l   d   !
72 101 108 108 111 44 32 119 111 114 108 100 33
  1. base64:

    Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format. In JavaScript, base64 encoding is often used for transmitting binary data, such as images or audio, over a network or for storing binary data in a text-based format, such as in a JSON file.

  2. window.atob
  3. Uint8Array
  4. buffer:

    In JavaScript, a buffer is a temporary storage area in memory that holds binary data. It is used to represent a sequence of bytes that may not be human-readable, such as the contents of a file or network packet

  5. Binary Data:

    Binary data is any data that is represented in a binary form, which means that it is made up of a sequence of 1s and 0s (binary digits). In computing, binary data is often used to represent non-textual data such as images, audio files, video files, and executable files.

Binary data is typically stored and processed using binary formats such as the binary file format, which is a format that stores data in a binary form that is optimized for storage efficiency and processing speed. Binary data can be read and written using a variety of programming languages and APIs, including JavaScript, Python, C++, and Java.

In JavaScript, binary data can be represented using several types of objects, such as ArrayBuffer, Uint8Array, and Blob. For example, the ArrayBuffer object represents a fixed-length binary buffer, while the Uint8Array object represents an array of 8-bit unsigned integers that can be used to manipulate binary data.

Binary data is also commonly transmitted over networks using binary protocols such as the TCP/IP protocol suite, which is used for communication over the internet. Binary data can be encoded and decoded using various encoding schemes, such as base64 encoding, which allows binary data to be transmitted over text-based protocols such as HTTP.

reboottime commented 1 year ago

FAQs

  1. why buffer

    Buffers are often used in file manipulation because files are typically stored in a binary format that consists of a sequence of bytes. Buffers provide a way to read and manipulate binary data directly in memory, without having to convert it to a different format first.

When reading from or writing to a file, buffers can be used to load the contents of the file into memory or to write new data to the file. For example, when reading a PDF file, we can use a buffer to load the contents of the file into memory as a Uint8Array, which can then be passed to a PDF library for parsing or manipulation.

Similarly, when writing to a file, we can use a buffer to store the data to be written to the file in memory before writing it to disk. This can be more efficient than writing to the file directly, as it reduces the number of disk writes required.

Buffers can also be used for various other file manipulation tasks, such as searching for patterns in binary data or performing byte-level transformations on the data. By working with binary data in memory using buffers, we can perform these tasks more efficiently and with greater control over the data than we would be able to with text-based file manipulation techniques.

  1. Bytes vs Bits One byte is equivalent to eight bits. A bit is considered to be the smallest unit of data measurement. A bit can be either 0 or 1.