Один из самых удобных способов записать данные это использование готовых форматов, такие как 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
BREAKING ⚠️🚨
⛴️⛴️⛴️ After months of failed negotiations, the @gazafreedomflotilla campaign in Turkiye @mavimarmaratr started the #FreedomWatch , a non-violent direct action with hundreds of people to free our boats from Hyadarpasa port in Istambul. The demonstrators blocked the port entrance and peacefully chained themselves to the gates.
🚨 LIVE NOW: https://www.instagram.com/mavimarmaratr?igsh=emNib2ZtZHFjZTFj
🇵🇸🍉 The objective of this inspiring action is that the we can finally sail to #Gaza to take desperately needed humanitarian aid and break the genocidal siege that Israel established on Gaza since 2007.
⛴️ Our protests in Turkiye will continue until our boats are free to sail, since they have all the necessary documentation and meet all the necessary requirements to do so. Please help us share this important action to #BreakTheSiege and to create a people´s humanitarian corridor in Gaza. When governments fail, we sail! #FreedomFlotilla#WeWillSail#LetThemSail🇵🇸
After prolonged negotiations with the Dutch Port Authority, ‘Handala’ is finally docked in Rotterdam! The Freedom Flotilla Coalition had organized a place to dock with Rotterdan City Marina but for undisclosed reasons, were prevented from docking in the planned location. This delay impacted our peaceful event and demonstration to welcome ‘Handala’ where children had drawn pictures and letters of support to send to Palestinian people in Gaza.
John Turnbull, representative of Canada Boat to Gaza, said “while engaging on this mission, the Palestinians are teaching us how to resist”.
Handala will continue to challenge the complicity of European countries on a journey to break the siege of Gaza. Next stop, London!
#breakthesiege#endtheblockade#gaza#palestine#freegaza#freepalestine#weaillsail#letthemsail#handala
Robert has long fought alongside Palestinians and isn't stopping now. Having spent time in Palestine documenting horrific human rights abuses by Israeli forces, he has seen the brutality of the occupation first hand. Despite the extreme difficulty in leaving his children and partner back home in what he describes as a "grieving process", he shares how important it is to use his privilege to be a part of the collective effort to break the siege on Gaza. As we have witnessed over the course of 9 months and 76+ years prior, we cannot fathom or predict the IOF's brutality or what they are capable of if they intercept 'Handala' in international waters. So we need your help in keeping Robert as safe as possible. We need your help in demanding safe passage for all volunteers onboard our Flotillas. Please share our videos, tag your politicians and ensure that we reach Gaza safely. #endtheblockade#breakthesiege#robertmartin#freepalestine#freegaza#endtheoccupation#solidarity#wewillsail#letthemsail
Palestinians in Gaza are being forced to endure a “vicious cycle of malnutrition, infection, wounds breaking down, more infection, more malnutrition”, explains British surgeon haunted by Gaza horrors. Professor Nick Maynard has only just arrived back in the UK after lending his expertise in Gaza where he witnessed teenagers with treatable, survivable injuries, whose bodies tragically shut down due to malnutrition. We need to break the siege of Gaza. We need to ensure the borders are opened to be able to provide medical aid and food to these teenagers and their families immediately. This could not be more urgent. #BreakTheSiege#AllEyesOnRafah#EndTheBlockade#GazaBlockade#FreedomFlotilla#WeWillSail#LetThemSail#Rafah#NickMaynard
The demonstration to release our Flotilla ships currently being prevented from leaving port by the Turkish Port Authorities, continues in Istanbul. We need your help in getting international media to cover this historic protest and help put pressure on the government to release our ships, ensuring we can sail towards Gaza.
HOW TO HELP:
1. Call, email and/or demonstrate at Turkish embassies and consulates and demand that the Freedom Flotilla ships be released and allowed to deliver aid to Gaza immediately.
2. Tag mainstream accounts in this post or when you share our photos to your stories.
3. Message the social media page of the Ministry of Transport and Foreign Affairs @tcdisisleri and @uabakanligi on IG and on X
4. Share our videos using the hashtags #WeWillSail and #LetThemSail tagging @tcdisisleri and @uabakanligi
#WeWillSail#LetThemSail#TheFreedomFlotilla#FFC#Istanbul#Turkiye#Turkey#MaviMarmara