1
00:00:00,270 --> 00:00:06,990
In this lecture, we're going to decode the base 64 string into binary data in the resource section

2
00:00:06,990 --> 00:00:11,220
of this lecture, I provide a link to a crate called Base64.

3
00:00:11,580 --> 00:00:16,020
It's a simple crate for encoding and decoding base64 values.

4
00:00:16,350 --> 00:00:20,190
We're going to use it to convert the string back into binary data.

5
00:00:20,520 --> 00:00:24,930
First, let's copy the installation code from the documentation page.

6
00:00:27,390 --> 00:00:30,510
Next, open the cargo configuration file.

7
00:00:33,000 --> 00:00:36,870
We level the dependencies table paste in the installation code.

8
00:00:39,310 --> 00:00:43,900
Lastly, let's use it in our project or when the library file.

9
00:00:46,360 --> 00:00:51,790
At the top of the file, we're going to import a function called Base 64 decode.

10
00:00:54,410 --> 00:00:58,970
The decode function will convert a base 64 value into a vector.

11
00:00:59,210 --> 00:01:00,830
Let's use it in our function.

12
00:01:01,100 --> 00:01:07,970
Before we do, I'm not interested in logging the file anymore lets you place the encoded file argument

13
00:01:07,970 --> 00:01:11,660
with a string that says the following Grayscale called.

14
00:01:14,180 --> 00:01:17,120
Next, let's begin decoding the value.

15
00:01:17,390 --> 00:01:22,790
We're going to store the binary data in a variable called base 64 two vector.

16
00:01:25,320 --> 00:01:31,470
The value for this variable will be the decode function with the encoded file argument passed in.

17
00:01:34,120 --> 00:01:40,330
If we hover our mouse over this function will be given more information about the type of value returned

18
00:01:40,330 --> 00:01:41,320
by this function.

19
00:01:41,680 --> 00:01:43,990
It's going to produce a result type.

20
00:01:44,410 --> 00:01:47,230
A few lectures ago, we talked about this type.

21
00:01:47,650 --> 00:01:52,780
Decoding a file can potentially cause an error for demonstration purposes.

22
00:01:52,930 --> 00:01:55,630
We're going to assume the file can be decoded.

23
00:01:56,050 --> 00:01:59,290
We'll change the unwrap function to grab the results.

24
00:02:01,930 --> 00:02:07,330
We should check the type of value wrapped by a resort type, according to the editor.

25
00:02:07,510 --> 00:02:13,180
The type for the successful result will be a vector with a collection of UAH values.

26
00:02:13,570 --> 00:02:16,330
The U8 type is a type for a numbers.

27
00:02:16,600 --> 00:02:18,370
The letter u stands for.

28
00:02:18,370 --> 00:02:22,450
Unsigned, unsigned numbers are always positive.

29
00:02:22,870 --> 00:02:25,300
Binary data is always positive.

30
00:02:25,540 --> 00:02:27,940
We don't need to store negative numbers.

31
00:02:28,420 --> 00:02:34,690
Let's log a message to let us know the value was decoded below the variable called the log function

32
00:02:34,690 --> 00:02:36,040
with the following message.

33
00:02:36,310 --> 00:02:37,450
Image decoded.

34
00:02:40,310 --> 00:02:45,530
Next, let's try uploading an image, open the console in the browser.

35
00:02:45,770 --> 00:02:48,170
After doing so, upload an image.

36
00:02:50,570 --> 00:02:57,610
And the council will find two logs our robust application is telling us the greyscale function has been

37
00:02:57,620 --> 00:03:00,230
called and the image has been decoded.

38
00:03:00,620 --> 00:03:01,190
Awesome.

39
00:03:01,370 --> 00:03:03,200
We can start to load the image.

40
00:03:03,440 --> 00:03:06,080
Let's take care of this step in the next lecture.

