<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Andrew Alvarez</title>
    <description>The latest articles on Forem by Andrew Alvarez (@aalvarez89).</description>
    <link>https://forem.com/aalvarez89</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F353707%2F68acb2e6-00b2-4d24-a183-2d1ad04d9988.png</url>
      <title>Forem: Andrew Alvarez</title>
      <link>https://forem.com/aalvarez89</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/aalvarez89"/>
    <language>en</language>
    <item>
      <title>An open discussion: What happened to Front-end positions?</title>
      <dc:creator>Andrew Alvarez</dc:creator>
      <pubDate>Wed, 28 Aug 2024 19:23:26 +0000</pubDate>
      <link>https://forem.com/aalvarez89/an-open-discussion-what-happened-to-front-end-developers-3ol6</link>
      <guid>https://forem.com/aalvarez89/an-open-discussion-what-happened-to-front-end-developers-3ol6</guid>
      <description>&lt;p&gt;Hello DEV community! I wanted to raise up a discussion after a trend I've been seeing for a while. For some context, I started as a front-end developer about 7 years ago and eventually transitioned to the full-stack development positions I've been working on (mostly on startups) due to having to fill those gaps. I love writing front-end code, I've always engaged faster with the products I build by having visual components to interact with.&lt;br&gt;
 Now, I've been watching this trend on job listing websites where there's barely any front-end jobs, almost everyone wants/requires full-stack devs. &lt;br&gt;
So naturally, I start posing questions... Is this the death of front-end careers on corporate companies? Does no one acknowledge the importance of dedicated front-end developers? Is this a product of the ignorance of non-technical people that revolve the industry?&lt;/p&gt;

&lt;p&gt;What do you guys think? &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>jobsearch</category>
      <category>frontend</category>
      <category>career</category>
    </item>
    <item>
      <title>How to be a Hackerman</title>
      <dc:creator>Andrew Alvarez</dc:creator>
      <pubDate>Tue, 12 Jan 2021 00:54:23 +0000</pubDate>
      <link>https://forem.com/aalvarez89/how-to-be-a-hackerman-hmj</link>
      <guid>https://forem.com/aalvarez89/how-to-be-a-hackerman-hmj</guid>
      <description>&lt;p&gt;Working with computers or programming is more than having the brains to come up with code and programs. You'll notice more than one coding instructor going backspace letter by letter to fix a typo, or someone dragging their mouse from the top of the document until the bottom to select everything (just press &lt;code&gt;Ctrl+A&lt;/code&gt; for the love of Shia Labeouf, just do it). I have found out that using the mouse incredibly hinders your speed and makes us think more than twice even the most simplest of decisions.&lt;/p&gt;

&lt;p&gt;I would like to teach you a set of skills that will improve your speed and performance and help you be anywhere as cool as this guy:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8gd5pnqf89imwht5uiid.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F8gd5pnqf89imwht5uiid.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclaimer: This guide is meant to work on Windows with WSL (Windows Subsystem for Linux), any Linux distro and MacOS.&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;distro&lt;/code&gt; means distributable, and its just a tailored version of Linux for certain specific needs. For example, Red Hat is the enterprise version, Mint is a general customizable build, and Raspbian is optimized for Raspberry PIs. &lt;br&gt;
I recommend Ubuntu 20.04 since it's user friendly and has a lot of support.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Think of your terminal as the manual way to operate your computer without a graphic interface.  Everything can be controlled via keyboard, you just have to know how to access what you need. &lt;br&gt;
Typing is the Hackerman way. &lt;/p&gt;
&lt;h3&gt;
  
  
  Ergo, lesson 1:  Learn them hotkeys.
&lt;/h3&gt;

&lt;p&gt;Now, how can I navigate around if I can't see anything or don't have anything to click?&lt;/p&gt;

&lt;p&gt;The first command you'll enter will be &lt;code&gt;pwd&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pwd
/user/kweizar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a &lt;strong&gt;path&lt;/strong&gt;, it's the address that leads to your &lt;strong&gt;Present Working Directory&lt;/strong&gt; on the computer's file system. Paths are case sensitive, so mind what you type.&lt;/p&gt;

&lt;p&gt;You can move between directories by using the &lt;code&gt;cd path&lt;/code&gt; command, cd stands for &lt;strong&gt;Change Directory&lt;/strong&gt;.&lt;br&gt;
There are many options you can pass as the cd command argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd 
/  : go to the root directory of your system.
.. : go to the parent directory // /user in this case
/user/kweizar/photos : an absolute path.
~/photos 
// or       } these two are relative paths.
./photos 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;More on absolute and relative paths later on.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcni3nr5cyv61ebsndw3w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fcni3nr5cyv61ebsndw3w.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Assume you are on the D/ folder, invoking &lt;code&gt;cd ..&lt;/code&gt; would take you to C/, &lt;code&gt;cd ~&lt;/code&gt; would take you to A/ since it's assigned as your &lt;strong&gt;home&lt;/strong&gt; directory. &lt;br&gt;
The command &lt;code&gt;cd /&lt;/code&gt; would take you to the root folder and invoking &lt;code&gt;cd .&lt;/code&gt; wouldn't do anything since you'd be navigating to the same folder.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This concludes the &lt;strong&gt;Navigation&lt;/strong&gt; part, we're now able to go to any directory we require.&lt;/p&gt;

&lt;p&gt;It's important to note that everything on your computer are &lt;strong&gt;files&lt;/strong&gt;. These follow a parent/child hierarchy starting from root (/) and keep branching out like a tree. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Directories&lt;/strong&gt; are files too; they possess extra metadata that greets them their "folder" properties.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Tip: File extensions are actually not required, they just help the OS associate the program that's meant to open that specific type of file.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, we'll want to get some &lt;strong&gt;Information&lt;/strong&gt; of our surroundings. Let's use the &lt;code&gt;ls&lt;/code&gt; command to list the content of the current directory&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls
photos/
documents/
main.go
calculator
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our terminal prints out all of the files in /user/kweizar&lt;br&gt;
We can also combine the command with a path and check remotely the content of that directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ ls ./photos/event/
photo1.jpg
photo2.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait, what the heck is &lt;code&gt;.&lt;/code&gt; ? This is an &lt;strong&gt;alias&lt;/strong&gt; that represents the directory you're currently at. There are others like &lt;code&gt;..&lt;/code&gt; which as mentioned above, goes to the parent directory.&lt;/p&gt;

&lt;p&gt;We printed out information that's already irrelevant to us, let's clear the screen out for less clutter. You can type &lt;code&gt;clear&lt;/code&gt; or press &lt;code&gt;ctrl + L&lt;/code&gt; and reset your console prompt screen.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;🪧 To open the console's manual use the &lt;code&gt;man man&lt;/code&gt; command. It will contain the instructions to open the multiple sections of the manual.&lt;br&gt;
This contains information for the shell commands (like ls, cd, etc.), system calls, the C and C++ libraries and their specifications, and many others. Combine &lt;code&gt;man&lt;/code&gt; with other commands to get their specific manual pages. &lt;br&gt;
Always refer to this guide first when you need thorough documentation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you start building a project, you're going to have to create files and folders.&lt;br&gt;
To create a file, use the &lt;code&gt;touch&lt;/code&gt; command. This will create a blank file with the specified name.&lt;br&gt;
To create a folder, use the &lt;code&gt;mkdir&lt;/code&gt; command.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;📢 Avoid using spaces in names, preferably use a naming format system like camelCase or snake_case and stick to it!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You will combine 99% of the commands with a filepath. I will introduce two news pattern for commands though, take for example the &lt;code&gt;cp&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Pattern 1:
// command source_path destination_path
$ cp ./photos/event/photo1.jpg .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You guessed correctly, cp is the copy command. Now a copy photo1.jpg exists in my current directory.&lt;/p&gt;

&lt;p&gt;You can also move files with mv, this is also the command to rename a file, just specify the new name at the destination path!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mv ./photos/event/photo1.jpg ./movedpicture.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now photo1.jpg will be moved and renamed to my current directory as movedpicture.jpg&lt;/p&gt;

&lt;p&gt;I'll use the &lt;code&gt;mkdir&lt;/code&gt; command for our second pattern.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Pattern 2:
// command destination_path1 destination_path2 destination_path3 ...
$ mkdir music videos pictures
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create three separate folders called music, videos and pictures.&lt;/p&gt;

&lt;p&gt;We've learned enough for today, in no time you will be speedily hacking into any mainframe.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Takeaway:
-Use the keyboard!
-Learn the shortcuts.
Information commands:
    -pwd
    -ls
    -man
Navigation:
    -cd
File Management:
    -touch
    -mkdir
    -mv
    -cp
-Command Patterns
-Aliases
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is my first part of the &lt;code&gt;How to be a Hackerman&lt;/code&gt; series. I hope to cover more themes like programs, Vim, Bash Scripts, Piping, Regex, more hotkeys and tips to control your shell, your editor and your OS.&lt;/p&gt;

&lt;p&gt;Thanks for reading and let me know if you'd like me to expand on an topic of your interest.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>bash</category>
      <category>hackerman</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Async Components, FileReader, and Angular</title>
      <dc:creator>Andrew Alvarez</dc:creator>
      <pubDate>Sat, 21 Mar 2020 21:43:46 +0000</pubDate>
      <link>https://forem.com/aalvarez89/async-components-filereader-and-angular-1fdd</link>
      <guid>https://forem.com/aalvarez89/async-components-filereader-and-angular-1fdd</guid>
      <description>&lt;p&gt;The problem: User input can't be trusted. When a file is uploaded to the internet, you can check on its Mime type, but can you trust it?&lt;/p&gt;

&lt;p&gt;While developing a drag and drop interface to upload media, my partner and I architected a series of processes to reduce the load on the server-side. &lt;/p&gt;

&lt;p&gt;We built an app that took audio and video and sent it to a google API for further processing. We didn't want the server to perform file validation since that we would need processes to deal with garbage data. We thought it might be a better idea to validate our media on the front-end to only send the right type of files.&lt;/p&gt;

&lt;p&gt;Let's say you upload a .html file and check on its type, you'll get "text/html"; when you upload a .mp3 file you get "audio/mpeg".&lt;br&gt;
So what's the problem with this? The browser is reading correctly your files! But it actually isn't.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PSRhhlqB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media1.giphy.com/media/9DgcVlvwcAAjetmNrp/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PSRhhlqB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://media1.giphy.com/media/9DgcVlvwcAAjetmNrp/giphy.gif" alt="Nani!?"&gt;&lt;/a&gt;&lt;/p&gt;
NANI!?



&lt;p&gt;If I change my audio file's extension from .mp3 to .txt, yes you'll "break" your file but you'll also be able to fool the browser as it will scan it and output "text/plain as it's Mime type.&lt;br&gt;
No one wants this to happen, we need to ensure the integrity of our app.&lt;br&gt;
The solution: Our Angular component needs to read the file and determine its actual content by its Magic Numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/*
In my component, I have declared a method called validateMime, 
it takes a Blob type since its what we get when our files go online.
*/&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;DragAndDrop&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;validateMime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Blob&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Our validation implementation goes here&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;readAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Blob&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Our FileReader logic goes here&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our tool to go is FileReader, a native JS object that allows us to read the file contents or the raw data buffer! You can read the specs of the FileReader object here.&lt;br&gt;
To execute FileReader, you'll have to call one of its 5 methods. In this case, I'll be using .readAsBinaryString()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;readAsBinaryString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="nx"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;mime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
                                &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                                &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bit&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; 
    &lt;span class="nx"&gt;bit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;codePointAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
                                &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;` - &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;mime&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; - `&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before we proceed, I must note that FileReader's methods work asynchronously, everything that happens within onload() won't be accessible on the outer scopes. We will have to change some of the component's methods. This is where async/await comes to the rescue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;readAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Blob&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;reader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;FileReader&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
      &lt;span class="nx"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
                               &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                               &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bit&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; 
        &lt;span class="nx"&gt;bit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;codePointAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
                                       &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nx"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onerror&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;reject&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Error&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Unable to read..&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nx"&gt;reader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;readAsBinaryString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our method returns a promise that will either execute its reject statement if for some reason it can't read the file or it will return the resolved value if it succeeds. The blob yields an ArrayBuffer type value which we'll just slice to get the four first bytes. These will tell us the real type of the file. The method chain will transform these bytes from Unicode into a string that represents the Magic Numbers of our file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;validateMime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Blob&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;contentBuffer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;readAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="c1"&gt;// Validation Process&lt;/span&gt;
        &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;acceptedMimeTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mimetype&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;contentBuffer&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;mimetype&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;magicNo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;isValid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; 
    &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, processFile() is an async method. It will await until readAsync returns (asynchronously) a value to assign it to contentBuffer, a variable I created to compare its value to a list of the accepted Mime Types for my app. If the Mime type shows up in my list it'll return true and it will accept my file!&lt;/p&gt;

&lt;p&gt;I hope you liked this article, feel free to give me feedback or contact me if you have any questions. I will keep posting the challenges I keep encountering when developing apps and narrate how I solved them.&lt;br&gt;
Thank you for reading!&lt;/p&gt;

</description>
      <category>angular</category>
      <category>filereader</category>
      <category>async</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
