Один из самых удобных способов записать данные это использование готовых форматов, такие как JSON или YAML.
Из плюсов такого подхода стоит отметить вот что:
🔸 готовый, повсеместно используемый и поддерживаемый формат
🔸 простой и понятный файл, удобочитаемый для человека
🔸 можно легко редактировать в любом текстовом редакторе без специальных программ и библиотек
Но есть и минусы
🔹 затраты времени при записи файла (кодирование данных в нужный формат строки)
🔹 затраты времени при чтении файла (декодирование данных в Python объекты)
🔹 размер файла увеличивается из-за разметки данных (скобки, запятые, переносы, отступы...)
🔹 перед записью все данные должны быть помещены в память в полном объёме (не всегда)
🔹 при чтении необходимо считать весь файл в память и только потом декодировать данные
Если нужно писать немного данных в несколько файлов, то затраты по времени не ощутимы. Обычно это файлы конфига или какие-либо метаданные. Это отличный вариант под такие задачи.
Есть и другой поход к записи файлов - это бинарные файлы. Используется, когда данных достаточно много и никто их не собирается читать глазками😳.
🔸 очень быстрая запись
🔸 чтение значительно быстрей чем JSON, YAML итд
🔸 размер файла значительно меньше, так как нет разметки
🔸 можно записывать данные по мере поступления не загружая всё в память
🔸 можно извлечь любую часть данных независимо
Из минусов
🔹 нужно определить свой формат записи данных (если не используете готовую спецификацию определённого формата)
🔹 не получится открыть файл и визуально понять что там записано, а для чтения файла потребуется знать его спецификацию.
🔹 не так-то просто создать такой файл без специальной библиотеки
В таком виде удобно записывать большой массив любых однородных данных. Например, мониторинг валютной биржи или кэшированная анимация 3D геометрии.
(Это не означает что нельзя записать данные разного типа, просто это будет не так удобно)
Представьте себе JPG-картинку. По сути это немного мета-информации и большой массив пикселей. Тоже самое со звуком или видео файлом. Поэтому, если вы попробуете открыть картинку в текстовом редакторе вы увидите что-то вроде такого
f15d cd29 a564 4578 ...
09e2 9bc4 a696 1253 ...
84e9 4de1 3b23 c24a ...
2534 5161 28e0 709d ...
...
Это и есть записанные байтики. И для их чтения требуется определённый софт который знает что с ними делать. Под каждый тип файла.
К чему это я? Читайте в следующем посте...
#tricks#basic
🚗💥 Introducing the Manhart MHXM 900! 💥🚗
Get ready to experience the ultimate BMW XM upgrade! 🌟
🔧Power Boost: From a stock 748 hp and 1000 Nm to an astonishing 900 hp and 1200 Nm! 💪🔥
⚙️Suspension Upgrade: Featuring H&R springs for enhanced handling! 🛠️
🛞Stunning Wheels: Equipped with eye-catching 24-inch Manhart wheels! 😍
🌌Carbon Fiber Body Kit: Lightweight and aggressive styling that enhances performance! 🖤
🖌️Luxurious Interior: Finished in a sleek grey-orange scheme with leather, Alcantara, and carbon accents! ✨
#Manhart#MHXM900#BMW#Performance#Tuning#CarEnthusiast#LuxuryCars#CarbonFiber#Auto
🏎️ McLaren Artura gets a massive wing and body kit by Novitec
Novitec has added a giant wing mounted on pylons, along with a body kit, redesigned bumpers, and a new engine cover, all made of carbon fiber.
The exhaust system can be crafted from stainless steel or Inconel, with an option for a gold coating at extra cost. Not only does it enhance the engine's sound, but it also boosts its performance by an estimated 35 horsepower, according to the tuners.
#McLarenArtura#Novitec#carbonfiber#exhaustsystem#tuning#horsepowerboost
🚗✨ Restomod Magic: BMW 8 Series Reimagined! ✨🚗
Check out this stunning restomod of the first-generation BMW 8 Series! 🏎️💨
🔧 Upgrades Include:
- Carbon Fiber Panels: Lightweight and sleek! 🖤
- Powerful V10 Engine: Swapped from the BMW M5 (E60) and bored out to 5.8 liters! 💥
- Modern Interior Touches: Blending classic with contemporary! 🛋️
#BMW#Restomod#8Series#M5#CarEnthusiast#ClassicMeetsModern#CarbonFiber#V10Power#Auto🚘💫
🚗✨Brabus Transforms Mercedes-AMG SL into a 1000-HP Shooting Brake!🔥
The new body and aerodynamic features are crafted entirely from carbon fiber. The turbocharged V8 has been enlarged from 4.0 to 4.5 liters, and now, combined with an electric motor on the rear axle, the powertrain delivers a staggering 1000 HP and 1620 Nm of torque! 💪⚡
These bespoke three-door beauties will be built to order, tailored to individual specifications. Pricing is not publicly disclosed. 💎
#Brabus#MercedesAMG#ShootingBrake#1000HP#LuxuryCars#CarEnthusiasts#CustomCars#AutomotiveExcellence#CarbonFiber#Auto
🚗💨 Introducing the Acura Integra Type S with HRC Factory Tuning! 🔥✨
Get ready to be amazed by the incredible upgrades:
🔹 Aggressive Front Bumper with an enhanced splitter
🔹 Sleek Rear Bumper featuring a diffuser
🔹 Carbon Fiber Hood for that lightweight edge
🔹 Forged 19-inch Wheels wrapped in Pirelli P Zero Trofeo R tires
🔹 Stunning Carbon Fiber Wing on aluminum supports
To lighten the load:
🔸 Carbon Fiber Rear Doors
🔸 Recaro Seats for ultimate comfort and support
🔸 Strut Brace replacing the rear bench for added rigidity
And let’s not forget the performance upgrades:
🔹 Coilover Suspension for precision handling
🔹 Six-Piston Brembo Brakes up front for unmatched stopping power
This beast is built for the track! 🏁💥
#AcuraIntegraTypeS#HRC#FactoryTuning#CarEnthusiast#Performance#CarbonFiber#Brembo#Pirelli#Auto
Just sold at auction! 🚗💰
This stunning Alfa Romeo 2000 GTV restomod with a carbon fiber body went for $220,000. 🤑
It took around four years to build this beauty, with everything from the chassis to the powertrain being completely overhauled.
🛠️ Italian specialists worked on the chassis and body, while the rest of the work was done in Canada. The upgraded 2.0 carbureted engine's exact output isn't specified, but the original Alfa Romeo 2000 GTV came with a 130-horsepower engine. 🏁
#AlfaRomeo#2000GTV#Restomod#CarbonFiber#Auction#ClassicCar#LuxuryCar#ItalianStyle🇮🇹